Repository navigation
Add noncopyable JSUniqueRef with heap references skipping deduplication - #830
Merged
Merged
Conversation
Contributor
|
I ran a js-framework-benchmark with ElementaryUI locally comparing current main with a version adopting JSUniqueRef (both PRs combined): Total is the time from the click to the end of the next paint (this is what the benchmark compares)
|
krodak
approved these changes
Nov 25, 2026
Member
|
I'd like to introduce #835 before this PR because it simplifies a lot of complexities this PR introduces (e.g. flag for deduplication, JSObject can be just a class holding unique ref, and conversion from unique ref to JSObject can be just a member init without no raw id takeover, etc...) |
kateinoigakukun
force-pushed
the
maxd/jsuniqueref-pt1
branch
from
November 27, 2026 10:12
4b9d57c to
a68ecd7
Compare
`JSUniqueRef` owns one JavaScript object reference and releases it in its `deinit`. Since the object heap no longer deduplicates references (#835), it needs no runtime support: it holds a reference exactly like `JSObject` does, without a Swift heap allocation. `JSObject` now stores a `JSUniqueRef`, and `init(_ ref: consuming JSUniqueRef)` is its only designated initializer. Releasing, including routing the release to the owner thread, happens in one place, `JSUniqueRef.deinit`, and `JSObject.deinit` is gone. `init(id:)` remains as a convenience initializer that adopts `id`. `JSClosure` and `JSOneshotClosure` still key their host functions by `ObjectIdentifier(self)`, so they still start from a placeholder reference of 0. They now hand the real reference over with `_replacePlaceholderRef(with:)`, which swaps it in and takes the placeholder out without releasing it. Co-authored-by: Max Desiatov <m_desiatov@apple.com>
kateinoigakukun
force-pushed
the
maxd/jsuniqueref-pt1
branch
from
November 27, 2026 10:24
a68ecd7 to
fb06cdb
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.
JSUniqueRefowns one JavaScript object reference and releases it when destroyed. Since #835 removed deduplication from the object heap, it needs no runtime support: it holds a heap reference exactly likeJSObject, but as a noncopyable value with no Swift heap allocation.JSObjectnow stores aJSUniqueRef, andinit(_ ref: consuming JSUniqueRef)is its only designated initializer:JSUniqueRef.deinit;JSObject.deinitis removed.init(id:)remains as an SPI convenience initializer that adoptsid, so existing callers and BridgeJS-generated code are unchanged.JSBigIntandJSSymboloverrideinit(_ ref:)instead ofinit(id:).JSClosureandJSOneshotClosurekeep keying host functions byObjectIdentifier(self). They start from a placeholder reference of 0 and hand over the real reference with_replacePlaceholderRef(with:), which never releases the placeholder.@_spi(BridgeJS)API:init(adopting:),id, andconsuming func unsafeTake(), all usingJavaScriptObjectRef.