Skip to content

perf: raise build target to ES2022#145

Open
layershifter wants to merge 8 commits intomicrosoft:mainfrom
layershifter:perf/es2022-spike
Open

perf: raise build target to ES2022#145
layershifter wants to merge 8 commits intomicrosoft:mainfrom
layershifter:perf/es2022-spike

Conversation

@layershifter
Copy link
Copy Markdown
Member

Summary

  • Flips target in tsdown.config.mts from es2019 to es2022. At ES2022, class fields, private identifiers, optional chaining, and nullish coalescing are emitted natively instead of being transpiled into helpers.
  • .browserslistrc (defaults, not IE 11) comfortably supports ES2022 — the defaults query resolves to browser versions from late 2021 onward, all of which ship ES2022 syntax.
  • downlevel-dts is unaffected: it only rewrites emitted .d.ts files and does not see the runtime target.

Stacking

PR 3 of the bundle-size reduction stack, stacked on #144 (perf: refactor Keyborg classes to closure-based factories). Until #144 merges, this PR's diff will include #144's commits. Please review only the final commit here; the prior commits are under review in #144.

Bundle size

Baseline = post-#144 tip.

Fixture Before (min / gz) After (min / gz) Delta
All exports 4.913 kB / 1.745 kB 4.632 kB / 1.655 kB −281 B min / −90 B gz (−5.7% / −5.2%)
createKeyborg() & disposeKeyborg() 4.677 kB / 1.693 kB 4.435 kB / 1.615 kB −242 B min / −78 B gz (−5.2% / −4.6%)
KEYBORG_FOCUSIN constant 64 B / 80 B 64 B / 80 B 0

Spike decision rule (≥2% min shrink, no gz regression) satisfied on both non-trivial fixtures.

Test plan

  • npm run build succeeds
  • npm test — 9/9 Playwright specs pass locally
  • npm run bundle-size shows shrinkage on both non-trivial fixtures

🤖 Generated with Claude Code

layershifter and others added 8 commits April 22, 2026 19:49
Four-PR plan to shrink keyborg's emitted bundle: drop the IE11
WeakRef shim, refactor classes to closures for better minification,
then measure ES2022 target and plain tsc emit as spikes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
First implementation plan in the bundle-size reduction stack.
Subsequent PRs (closure refactor, ES2022 spike, tsc-emit spike)
will get their own plans as the stack progresses.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
.browserslistrc excludes IE 11, so the shim's fallback path was
unreachable. Replace with native WeakRef, remove the companion
Disposable interface, and delete the unused KeyborgCore.isDisposed()
method (its body `return !!this._win` was inverted — returned true
before dispose — which confirms nothing on the supported path ever
called it).

Bundle-size deltas on measurement fixtures:
- All exports:                        -385 B min / -120 B gz
- createKeyborg + disposeKeyborg:     -385 B min / -124 B gz
- KEYBORG_FOCUSIN constant:           no change

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The deletion was intended in the previous refactor commit but got
dropped during a stash/pop round-trip. The file is already unused
(no importers) so the bundle shape is unchanged — this just removes
the now-dead file from the source tree.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces class KeyborgCore and class Keyborg with factory functions.
Per-instance state moves from this._x fields (which minifiers cannot
mangle at target: "es2019") to closure locals (which they can). Public
API unchanged: createKeyborg, disposeKeyborg, and the Keyborg type
(now an interface) keep the same shape. WindowWithKeyborg.__keyborg
retains its outer { core, refs } shape.

Bundle-size deltas vs post-PR-1 baseline:
- All exports:                        -1.693 kB min / -212 B gz
- createKeyborg + disposeKeyborg:     -1.693 kB min / -211 B gz
- KEYBORG_FOCUSIN constant:           no change

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
At es2022, class fields, #private syntax, optional chaining and
nullish coalescing are native — no transpilation helpers. The closure
refactor in microsoft#144 already eliminated the class bodies, so the remaining
wins come from lib-level features.

Bundle-size deltas vs post-microsoft#144 baseline:
- All exports:                       -281 B min / -90 B gz
- createKeyborg + disposeKeyborg:    -242 B min / -78 B gz
- KEYBORG_FOCUSIN constant:          no change

Decision rule (>=2% min shrink, no gz regression) satisfied:
min shrinks 5.2-5.7%, gz shrinks 4.6-5.2%.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@layershifter layershifter requested review from a team and mshoho as code owners April 22, 2026 18:31
@github-actions
Copy link
Copy Markdown

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
keyborg
All exports
6.991 kB
2.077 kB
4.632 kB
1.655 kB
-2.359 kB
-422 B
keyborg
createKeyborg() & disposeKeyborg()
6.755 kB
2.028 kB
4.435 kB
1.615 kB
-2.32 kB
-413 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
keyborg
KEYBORG_FOCUSIN constant
64 B
80 B
🤖 This report was generated against f85618e6335ccb113ed0d126ab3c27a1c4671821

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