Skip to content

perf: tree-shake web-haptics out of triggerHaptic imports (−62% gzip) - #42

Merged
joeblau merged 2 commits into
mainfrom
perf/36-tree-shake-presets
Oct 21, 2026
Merged

joeblau merged 2 commits into
mainfrom
perf/36-tree-shake-presets

Conversation

@joeblau

@joeblau joeblau commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Closes #36

What

trigger.ts now reads the 11 presets from a local src/presets.ts literal instead of importing defaultPatterns from web-haptics. web-haptics is only imported for types there. HapticTarget still uses WebHaptics unchanged. A new drift test (test/presets.test.ts) deep-equals the local table against web-haptics' defaultPatterns, so a dependency bump that changes presets fails CI.

Implemented with the Codex CLI on the shared box and verified by hand.

Benchmark (npm run bench, same box, back-to-back)

Bundle (esbuild, ES2020, React external) main 78ec2f2 this PR
triggerHaptic gzip bytes 3,313 1,273 (−2,040 B, −62%)
triggerHaptic min bytes 9,110 3,193
triggerHaptic web-haptics bytes 6,440 0
Full ESM gzip bytes 4,514 4,541 (+27 B, duplicated table)
Full CJS gzip bytes 4,873 4,881 (+8 B)
HapticTarget gzip bytes 3,781 3,782

Byte counts are deterministic. Runtime timings did not change beyond noise.

Verification

  • npm run lint, typecheck (ESM+CJS+DTS build), coverage (135 tests, 100% statements/branches/functions/lines), size, pack:check pass locally.
  • SSR: the preset table is a plain literal. The imperative path no longer evaluates the web-haptics module, which removes a navigator read at module load.
  • Behavior: same patterns, same navigator.vibrate output (existing trigger tests unchanged and passing).

Device-testing notes

These are simulated-browser and bundler numbers (Node 24, jsdom/esbuild on a Linux box), not physical-device measurements. No physical device was used. Physical iPhone/Android/iPadOS/VoiceOver certification remains tracked in #9.

@joeblau
joeblau merged commit 3b321e1 into main Oct 21, 2026
5 checks passed
@joeblau
joeblau deleted the perf/36-tree-shake-presets branch October 21, 2026 00:46
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.

Tree-shake web-haptics out of imperative triggerHaptic imports (−2 KB gzip)

1 participant