perf: inline feature bits inside the library - #183
Open
LadyBluenotes wants to merge 2 commits into
Open
LadyBluenotes wants to merge 2 commits into
LadyBluenotes wants to merge 2 commits into
Conversation
Internal code uses an inlined const enum; the public Feature object keeps the forward mapping only, so bundles that never import it carry nothing and bundles that do skip the reverse-mapping IIFE.
🦋 Changeset detectedLatest commit: b7b9088 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
LadyBluenotes
force-pushed
the
perf/feature-const-object
branch
from
September 11, 2026 21:57
39b8c49 to
dbaf984
Compare
lxsmnsyc
previously approved these changes
Sep 12, 2026
Owner
|
This will hit Solid because of the rename. |
Restore the exported runtime enum so the published declaration is unchanged, and keep the internal const enum for inlining.
lxsmnsyc
approved these changes
Sep 12, 2026
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.
Every
Feature.Xread inside the library now goes through an internalconst enum(FeatureFlag), so each check inlines to a literal instead of a property read on the enum object. The exportedFeaturestays a runtimeenum, byte for byte the same declaration as before, soFeature.Xreads, bitwise combinations,Feature[1]reverse lookups andFeatureas a type all keep working. A test asserts the public values match the internal bits and that they coverALL_ENABLED.An earlier revision of this PR replaced the public enum with an
as constobject plus a union type. That changed the published declaration fromdeclare enum Featureto aconstand atype, which is an API change for anyone typing a bit combination asFeature, so it was reverted here. The size win from that revision only applied to bundles that importFeature(about 40 B gzip), and the internal inlining is kept.Measured as minified browser ESM consumer bundles (ES2020) with esbuild 0.28.2 and Rolldown 1.2.5, gzip level 9 and Brotli quality 11, compared with
a054acc:serialize, the client set and the server set are unchanged within a few bytes, since the unused enum was already tree-shaken by the@__PURE__annotation on its IIFE.On Node 24.12.0,
serialize,toJSON,fromJSONandfromCrossJSONover a 300-object graph (dates, maps, sets, typed arrays, errors) stay within ±2% ofa054accacross five alternating samples of 60 calls, which is inside run-to-run noise.Tests: 907 passing.