feat: Add per-class identityMode via @JS macro parameter#3
Merged
Conversation
f898b82 to
f290715
Compare
Collaborator
Author
Benchmark Results (PR #3 vs PR #2)Release build, adaptive sampling with IQR outlier removal. arm64-apple-macosx26.0, Node.js v22.22.0. Moving identity mode from runtime flag to codegen-time decision improved performance across the board. V8 JIT optimizes better when
Memory unchanged: 271 MiB → 41 MiB peak heap (6.6x), 271 MiB → 21 MiB retained (12.9x). |
f290715 to
b6b052f
Compare
Add identityMode: Bool parameter to @js macro. When set to true on a class, that class uses pointer identity caching. When false or not set, the class uses the bridge-js.config.json default. Identity is resolved entirely at codegen time - no runtime option. Classes with identity mode get static __identityCache passed to __wrap. Classes without it pass null. No runtime branching in __construct. Resolution: @js(identityMode: true/false) > bridge-js.config.json > default (off).
b6b052f to
b47bd9c
Compare
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.
Overview
Add
identityMode: Boolparameter to the@JSmacro, enabling per-class opt-in to pointer identity caching. Identity is resolved entirely at codegen time - no runtime option.Resolution:
@JS(identityMode: true/false)>bridge-js.config.json> default (off).The runtime
options.identityModeoverride has been removed. Benchmarking both modes requires separate builds. This keeps the generated code simple: each class's__constructeither passes__identityCacheornullto__wrap, no runtime branching.Links
What changed
Macros.swift- AddedidentityMode: Bool = falseparameter to@JSmacro.BridgeJSSkeleton.swift- AddedidentityMode: Bool?toExportedClass.SwiftToSkeleton.swift- AddedextractIdentityModeparser, same pattern asextractNamespace/extractEnumStyle.BridgeJSLink.swift- Per-class codegen: classes with identity get__identityCachepassed to__wrap, others getnull. Removed globalshouldUseIdentityMap,identityModeruntime variable, andhasIdentitySupportcheck. AddedshouldUseIdentityCache(for:)helper.instantiate.d.ts/index.js/index.d.ts- RemovedidentityModefromInstantiateOptionsandOptionstypes. Removed runtime pass-through in node/browser init.IdentityModeClass.swift- Test input with@JS(identityMode: true), plain@JS, and@JS(identityMode: false).BridgeJSLinkTests.swift- Tests: per-class annotation parsing, config "pointer" + class override, skeleton-level assertions.Tested
swift test --package-path ./Plugins/BridgeJS- 107 tests pass./Utilities/format.swift- clean./Utilities/bridge-js-generate.sh- generated files up to date