Conversation
saghul
commented
Mar 31, 2026
bnoordhuis
approved these changes
Apr 1, 2026
The equality comparison functions (js_strict_eq2, js_strict_eq, js_same_value, js_same_value_zero) are pure read-only operations that don't need to own the values being compared. Change them to take JSValueConst (borrowed) instead of JSValue (owned), eliminating unnecessary js_dup/JS_FreeValue pairs.
When the input is already a JS_TAG_STRING, return it directly instead of going through JS_ToString (which dups) + JS_FreeValue (which frees the original), saving a redundant dup+free pair.
Extend JS_GetOwnPropertyInternal with a pflags out-parameter so callers that only need property flags can skip the js_dup of value/getter/setter fields. When desc is NULL and pflags is non-NULL, only the flags are written.
Add JS_DefinePropertyValueConst, JS_DefinePropertyValueInt64Const, and JS_CreateDataPropertyUint32Const that borrow their val parameter instead of consuming it. This eliminates unnecessary js_dup/JS_FreeValue pairs at call sites where callers were duping values only to have them immediately freed by the property definition function.
When the input is already an object, return it directly instead of going through JS_ToObject (which dups it) and then JS_FreeValue (which frees it), avoiding a pointless refcount increment/decrement.
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.
Some benchmark results (my system was not fully idle, so there might be some noise, I made several runs):
Micro-bench script:
bench_refcount.js