perf(ios): reuse and pre-prepare feedback generators to reduce impact latency#32
Open
magnuslo wants to merge 1 commit into
Open
perf(ios): reuse and pre-prepare feedback generators to reduce impact latency#32magnuslo wants to merge 1 commit into
magnuslo wants to merge 1 commit into
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
impact()andnotification()created a brand-newUIImpactFeedbackGenerator/UINotificationFeedbackGeneratoron every call and never calledprepare(). 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 forselectionStart()/selectionChanged().No public API change.
selectionStart/Changed/Endand bothvibrate(...)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()/CHHapticEnginework in #24 — that PR owns thevibrate(duration)path; this one only touchesimpact/notification.)Type of changes
(Performance refactor — non-breaking, no API change.)
Platforms affected
Tests
npm run lint(eslint + prettier + swiftlint) passes with 0 violations.npm run verify:webbuilds.Screenshots (if appropriate)
N/A (haptic feedback is not visual).