Skip to content

perf(ios): reuse and pre-prepare feedback generators to reduce impact latency#32

Open
magnuslo wants to merge 1 commit into
ionic-team:mainfrom
magnuslo:perf/ios-prepare-feedback-generators
Open

perf(ios): reuse and pre-prepare feedback generators to reduce impact latency#32
magnuslo wants to merge 1 commit into
ionic-team:mainfrom
magnuslo:perf/ios-prepare-feedback-generators

Conversation

@magnuslo

Copy link
Copy Markdown

Description

impact() and notification() created a brand-new UIImpactFeedbackGenerator / UINotificationFeedbackGenerator on every call and never called prepare(). That forces the Taptic Engine to cold-start on each trigger, which adds perceptible latency to the first (and every subsequent) impact.

This PR caches one generator per impact style plus the notification generator, calls prepare() when each is created, and re-prepare()s after every event so the next trigger stays warm. It mirrors the prepared-generator pattern the plugin already uses for selectionStart() / selectionChanged().

No public API change. selectionStart/Changed/End and both vibrate(...) overloads are untouched.

Context

Apple's prepare() documentation recommends preparing a feedback generator ahead of time so the Taptic Engine is warm when feedback is triggered, reducing latency. The current implementation never does this for impact/notification, so the engine cold-starts on each call. We observed a clear, perceptible improvement on a physical device after switching to cached + prepared generators.

(This is independent of, and does not overlap with, the vibrate() / CHHapticEngine work in #24 — that PR owns the vibrate(duration) path; this one only touches impact/notification.)

Type of changes

  • Fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Refactor (cosmetic changes)
  • Breaking change (change that would cause existing functionality to not work as expected)

(Performance refactor — non-breaking, no API change.)

Platforms affected

  • Android
  • iOS
  • Web

Tests

  • Verified npm run lint (eslint + prettier + swiftlint) passes with 0 violations.
  • Verified npm run verify:web builds.
  • Manually tested on a physical iOS device: impact/notification feedback fires with noticeably lower first-trigger latency than the stock create-per-call implementation, and repeated triggers stay warm. Selection and vibrate behavior unchanged.

Screenshots (if appropriate)

N/A (haptic feedback is not visual).

… latency

impact() and notification() created a new UIImpactFeedbackGenerator /
UINotificationFeedbackGenerator on every call and never called prepare(),
forcing the Taptic Engine to cold-start each time (perceptible latency on the
first fire). Cache one generator per impact style plus the notification
generator, prepare() them on creation, and re-prepare() after each event so the
next trigger stays warm. Mirrors the existing prepared-generator pattern already
used by selectionStart()/selectionChanged(). No public API change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant