Repository navigation
[JSC] JSObject::convertFromCopyOnWrite should allocate only what the caller needs - #79650
Open
sosukesuzuki wants to merge 1 commit into
Conversation
…e caller needs https://bugs.webkit.org/show_bug.cgi?id=330160 Reviewed by NOBODY (OOPS!). convertFromCopyOnWrite allocates a butterfly of nextLength(vectorLength), but it then copies the IndexingHeader from the old butterfly, so the new vectorLength is the old one and the extra capacity is never used. A store pays for memory it does not need, and a push right after the conversion allocates a larger butterfly and copies the elements again. This patch adds an additionalLength argument, the number of elements the caller is about to add. With 0, the conversion allocates only what the existing elements need. Otherwise it allocates a butterfly with room for them and records that in vectorLength. JSArray::pushInline passes 1, and all the other callers pass 0. DFG and FTL used to emit Arrayify before ArrayPush, which converted the array before pushInline could see it. ArrayPush no longer does so for Int32, Double and Contiguous arrays. Since publicLength equals vectorLength in a copy-on-write butterfly, the inline path never stores to it and always takes the slow path call. Baseline Patched array-copy-on-write-push 49.1493+-2.4547 ^ 33.1678+-2.1527 ^ definitely 1.4818x faster array-copy-on-write-first-store 90.8132+-1.9766 ^ 72.1276+-1.1986 ^ definitely 1.2591x faster Tests: JSTests/microbenchmarks/array-copy-on-write-first-store.js JSTests/microbenchmarks/array-copy-on-write-push.js JSTests/stress/array-push-copy-on-write.js * JSTests/microbenchmarks/array-copy-on-write-first-store.js: Added. (test): * JSTests/microbenchmarks/array-copy-on-write-push.js: Added. (test): * JSTests/stress/array-push-copy-on-write.js: Added. (shouldBe): (pushInt32): (pushDouble): (pushContiguous): (pushTwo): (pushTwoDoubles): (pushMixed): (pushNothing): (literalThenPush): (i.shouldBeArray.Object.keys): (i.shouldBe): (i.shouldBeArray): * Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::handleIntrinsicCall): * Source/JavaScriptCore/dfg/DFGOperations.cpp: (JSC::DFG::JSC_DEFINE_JIT_OPERATION): * Source/JavaScriptCore/runtime/JSArray.cpp: (JSC::JSArray::fastFill): (JSC::JSArray::fastCopyWithin): (JSC::JSArray::appendMemcpy): (JSC::JSArray::setLength): * Source/JavaScriptCore/runtime/JSArrayInlines.h: (JSC::JSArray::pushInline): * Source/JavaScriptCore/runtime/JSObject.cpp: (JSC::JSObject::convertFromCopyOnWrite): (JSC::JSObject::tryMakeWritableInt32Slow): (JSC::JSObject::tryMakeWritableDoubleSlow): (JSC::JSObject::tryMakeWritableContiguousSlow): (JSC::JSObject::deletePropertyByIndex): (JSC::JSObject::ensureLengthSlow): * Source/JavaScriptCore/runtime/JSObject.h: * Source/JavaScriptCore/runtime/JSObjectInlines.h: (JSC::JSObject::ensureWritable):
Collaborator
|
EWS run on current version of this PR (hash 2ab7318) Details |
This was referenced Nov 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.
2ab7318
2ab7318