Repository navigation
[JSC] Array profiles should not turn ordinary arrays into ArrayStorage - #75376
Open
sosukesuzuki wants to merge 1 commit into
Open
sosukesuzuki wants to merge 1 commit into
sosukesuzuki wants to merge 1 commit into
Conversation
Collaborator
|
EWS run on previous version of this PR (hash 8fef23c) Details |
sosukesuzuki
marked this pull request as draft
October 1, 2026 13:18
https://bugs.webkit.org/show_bug.cgi?id=325781 Reviewed by NOBODY (OOPS!). Freezing an array turns it into ArrayStorage. After that, two profiles start to turn ordinary arrays into ArrayStorage, and those arrays miss most of the array fast paths. 1. ArrayMode::fromObserved picks ArrayStorage with Array::Convert for a site that has seen both Contiguous and ArrayStorage. Arrayify then converts every array that comes to the site. 2. ArrayAllocationProfile picks ArrayStorage for a site when the last array allocated there has become ArrayStorage. The array builtins share their profiles in a realm. Passing one frozen array to `every`, or freezing one result of `map`, affects every caller. This patch stops that. 1. ArrayMode::fromObserved ignores ArrayStorage when the site has seen Undecided, Int32, Double or Contiguous too. If an ArrayStorage array then fails the check in optimized code, ArrayProfile remembers it and the next compilation uses Array::Generic. 2. ArrayAllocationProfile ignores the last array when it has become ArrayStorage. The site keeps allocating arrays as before, and only the arrays that need ArrayStorage are converted later. 3. Arrayify exits with SparseIndex instead of Uncountable when the index is sparse, and ArrayMode::refine uses Array::Generic for the site in the next compilation. A site that writes to a sparse index did not reach this exit when Arrayify converted the array to ArrayStorage first. The other sites already kept exiting here. Both profiles still pick SlowPutArrayStorage as before. Every array has it when having a bad time. Some JetStream 3 tests hit this. Counts in one run, before -> after: Arrayify to ArrayStorage Allocated as ArrayStorage proxy-mobx 23306 -> 0 219027 -> 0 babel-wtb 53886 -> 0 21265 -> 0 jsdom-d3-startup 3011 -> 0 20834 -> 0 These tests were neutral when I ran them locally. Tests: JSTests/stress/array-allocation-profile-should-not-select-array-storage.js JSTests/stress/array-should-not-be-converted-to-array-storage-by-frequent-frozen-arrays.js JSTests/stress/array-should-not-be-converted-to-array-storage-by-frozen-array.js JSTests/stress/array-without-elements-should-not-be-converted-to-array-storage-by-frozen-array.js JSTests/stress/arrayify-should-not-keep-exiting-for-sparse-index.js * JSTests/stress/array-allocation-profile-should-not-select-array-storage.js: Added. (shouldBe): (createWithPush): (createWithLiteral): (createWithNewArray): (createWithMap): (createDoubleWithPush): (createInt32WithNewArray): (createInt32WithConstantLiteral): (createEmpty): (test): * JSTests/stress/array-should-not-be-converted-to-array-storage-by-frequent-frozen-arrays.js: Added. (shouldBe): (create): (createFrozen): (isObject): (every): (some): (filter): (forEach): (at): (indexed): (forOf): (destructure): (store): (push): (test): * JSTests/stress/array-should-not-be-converted-to-array-storage-by-frozen-array.js: Added. (shouldBe): (create): (createFrozen): (isObject): (every): (some): (filter): (forEach): (at): (indexed): (forOf): (destructure): (store): (push): (test): * JSTests/stress/array-without-elements-should-not-be-converted-to-array-storage-by-frozen-array.js: Added. (shouldBe): (shouldNotBeCompiledRepeatedly): (first): (indexed): (forOf): (destructure): (store): (push): (test): * JSTests/stress/arrayify-should-not-keep-exiting-for-sparse-index.js: Added. (shouldBe): (shouldNotBeCompiledRepeatedly): (putAfterOptimized): (putOncePerArray): (putToArrayBecomingSparse): (read): * Source/JavaScriptCore/bytecode/ArrayAllocationProfile.cpp: (JSC::ArrayAllocationProfile::updateProfile): * Source/JavaScriptCore/bytecode/ArrayProfile.cpp: (JSC::ArrayProfile::computeUpdatedPrediction): * Source/JavaScriptCore/bytecode/ArrayProfile.h: (JSC::ArrayProfile::removeObservedArrayModes): (JSC::ArrayProfile::speculationFailedOnArrayStorage const): * Source/JavaScriptCore/bytecode/ExitKind.h: * Source/JavaScriptCore/dfg/DFGArrayMode.cpp: (JSC::DFG::ArrayMode::fromObserved): (JSC::DFG::ArrayMode::refine const): * Source/JavaScriptCore/dfg/DFGArrayifySlowPathGenerator.h: * Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::handleIteratorNext): * Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileArrayify):
sosukesuzuki
force-pushed
the
eng/array-profiles-should-not-select-array-storage
branch
from
October 1, 2026 13:56
8fef23c to
67fc02a
Compare
Collaborator
Collaborator
|
EWS run on current version of this PR (hash 67fc02a) Details |
sosukesuzuki
marked this pull request as ready for review
October 3, 2026 04:04
sosukesuzuki
added a commit
to oven-sh/WebKit
that referenced
this pull request
Oct 14, 2026
…kit-75376 [JSC] Array profiles should not turn ordinary arrays into `ArrayStorage` (cherry-pick WebKit#75376)
Jarred-Sumner
added a commit
to oven-sh/bun
that referenced
this pull request
Oct 15, 2026
…rchy exists beside it (#45272) ### What does this PR do? Bumps WebKit to `79f27e1945be`, the merge commit of oven-sh/WebKit#808. #### Bun did not see the limits of cgroup v2 on a host that also has a cgroup v1 hierarchy `navigator.hardwareConcurrency`, `os.availableParallelism()`, the number of threads that Bun starts (`bun fmt`, `bun lint`, `bun check`, `bun install`, the thread pool), `process.constrainedMemory()` and the memory that JavaScriptCore sizes its heap by were those of the whole machine. Whether a host has v1 or v2 was decided by the first line of `/proc/self/cgroup`. The kernel lists v1 hierarchies first, so one of them was enough, even a named one that has no controllers: ``` 1:name=systemd:/ 0::/system.slice/a.service ``` Under `systemd-run --scope -p CPUQuota=200% -p MemoryMax=1G`, on a machine with 64 cores and such a file: | | before | after | |---|---|---| | `navigator.hardwareConcurrency` | 64 | 2 | | `os.availableParallelism()` | 64 | 2 | | `process.constrainedMemory()` | 265981812736 | 1073741824 | Each controller is now read from v2 if there is a `0::/` line and no v1 line names it. A host with only v2, with only v1, or with systemd's hybrid layout gets the same answers as before. A v1 host where memory is mounted together with another controller (`3:cpu,cpuacct,memory:/a`) did not find the limit of its group either, and does now. #### What else the bump brings One change that is on the main branch of oven-sh/WebKit and not in the build that Bun pins: oven-sh/WebKit#785, "[JSC] Array profiles should not turn ordinary arrays into `ArrayStorage`", a cherry-pick of WebKit/WebKit#75376. ### How did you verify your code works? - New cases next to `process.constrainedMemory()` in `test/js/node/process/process.test.js`: six layouts, each in a user and mount namespace of its own, where a made-up directory is `/sys/fs/cgroup` and a made-up file is `/proc/self/cgroup`. They need no root, and are skipped where the host does not allow such a namespace. Before the bump the four layouts that always worked pass and the two above fail. In CI they run on Debian 13 (x64, aarch64, ASAN) and Alpine 3.23 (x64, aarch64), and are skipped on Ubuntu 25.04. - The numbers in the table, with real limits from systemd. Without the two properties it is 64, 64 and 265981812736 before and after. `os.cpus().length` is 64 in every case. - The rest of `process.test.js` gives the same results as on main. - oven-sh/WebKit#808 has a table of thirteen layouts for the file compiled on its own.
chicoxyzzy
reviewed
Oct 15, 2026
Comment on lines
+59
to
+60
| // An array that has become ArrayStorage does not tell us which type it had, so we learn nothing from it. | ||
| if (!lastArray || hasArrayStorage(lastArray->indexingType())) |
Member
There was a problem hiding this comment.
hasArrayStorage is only ArrayStorageShape. A slow-put array is a higher shape, and leastUpperBoundOfIndexingTypes is std::max, so that sample still replaces an Int32, Double, or Contiguous profile. hasAnyArrayStorage covers both.
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.
🛠 tv-sim
67fc02a
67fc02a