Repository navigation
Port bellard/quickjs@10c81b1 to fix GCC 14+ performance regression - #1744
Merged
Merged
Conversation
Port of bellard/quickjs@10c81b1 ("fixed large performance regression with recent GCC versions"). JS_MKVAL() only wrote the 32-bit int32 member of JSValueUnion and left the upper half of the union uninitialized. Since GCC 14, x86-64 code generation for such partially initialized 16-byte structs is much worse (GCC PR 114134, a regression from r14-2386): every js_int32() or js_bool() inlined into JS_CallInternal() becomes a movabs/and/or read-modify-write and the value makes a round trip through the stack. clang 21 emits some of the same masking sequences. Writing the whole 64-bit member avoids that. Unlike upstream, JS_VALUE_GET_SHORT_BIG_INT() also reads the 64-bit member because __JS_NewShortBigInt() builds its value with JS_MKVAL(). Reading the 32-bit member would return the wrong half on big-endian hosts. Co-authored-by: Fabrice Bellard <[email protected]>
gengjiawen
force-pushed
the
jsvalue-uint64
branch
from
September 23, 2026 02:41
b03d721 to
654bab5
Compare
saghul
approved these changes
Sep 23, 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.
Port of bellard/quickjs@10c81b1 ("fixed large performance regression with recent GCC versions").
JS_MKVAL()only writes the 32-bitint32member ofJSValueUnion, so the upper half of the union is left uninitialized. Since GCC 14, x86-64 code generation for such partially initialized 16-byte structs is much worse. Everyjs_int32()orjs_bool()inlined intoJS_CallInternal()becomesmovabs $0xffffffff00000000+and+orto merge the new value into the old register contents, and the value then makes a round trip through the stack with a 16-byte reload. This is GCC PR 114134, a regression from r14-2386 that is still open. Writing the whole 64-bit member avoids it.The change is limited to the non-NaN-boxing branch of
quickjs.h. The size and layout ofJSValuedo not change.Differences from upstream:
JS_VALUE_GET_SHORT_BIG_INT()also reads the 64-bit member. In ng,__JS_NewShortBigInt()builds its value withJS_MKVAL(), so reading the 32-bitshort_big_intmember returns the wrong half on big-endian hosts. On s390x with only upstream's hunk,7n / 2nthrows "BigInt division by zero" andtest_bigint.jsandtest_std.jsfail.JS_MKVAL()inline function gets the same change.The
int32member ofJSValueUnionis removed, as upstream does. Embedders that readv.u.int32directly should useJS_VALUE_GET_INT().Code size
JS_CallInternal(), x86-64, Release build. "Masks" countsmovabs $0xffffffff00000000, "16-byte stores" countsmovups %xmm, mem.Performance
V8 benchmark suite v7. Each benchmark runs a fixed number of iterations and the table shows wall time, master → this PR, best of 7 interleaved runs. The machine is a shared 8-vCPU Skylake VM, so differences of a few percent are noise.
Testing
make test,api-test, standalone test,ctest, full test262 with the 49 known errors and nothing newmake test,api-testcxxtestwith g++ and clang++make test,api-test-DJS_NAN_BOXING=0so the struct representation is used:make test,api-testmake codegenasdocs/docs/building.mddescribes:make test,api-test