[JSC] Improve worst case performance of Air stack allocation#61023
Merged
webkit-commit-queue merged 1 commit intoWebKit:mainfrom Mar 21, 2026
Conversation
Collaborator
|
EWS run on previous version of this PR (hash b0ad24b) Details
|
b0ad24b to
682b9b7
Compare
Collaborator
|
EWS run on previous version of this PR (hash 682b9b7) Details
|
682b9b7 to
4df3985
Compare
Collaborator
|
EWS run on previous version of this PR (hash 4df3985) Details |
4df3985 to
34741bb
Compare
Collaborator
|
EWS run on previous version of this PR (hash 34741bb) Details
|
Constellation
approved these changes
Mar 20, 2026
| otherSlots.append(otherSlot); | ||
| } | ||
|
|
||
| std::sort(otherSlots.begin(), otherSlots.end(), [](StackSlot* a, StackSlot* b) { |
Member
There was a problem hiding this comment.
You can use std::ranges::sort(otherSlots, [](...) {
Contributor
Author
There was a problem hiding this comment.
Ah, that's better. Also changed to use std::ranges::greater { }, &StackSlot::offsetFromFP.
And changed the upper_bound too to this syntax.
| auto sortByOffsetDescending = [](StackSlot* a, StackSlot* b) { | ||
| return a->offsetFromFP() > b->offsetFromFP(); // Negative, so sort descending | ||
| }; | ||
| std::sort(assignedEscapedStackSlots.begin(), assignedEscapedStackSlots.end(), sortByOffsetDescending); |
34741bb to
d04e195
Compare
Collaborator
|
EWS run on previous version of this PR (hash d04e195) Details |
d04e195 to
f5eac0f
Compare
Collaborator
|
EWS run on current version of this PR (hash f5eac0f) Details |
https://bugs.webkit.org/show_bug.cgi?id=310376 rdar://173019617 Reviewed by Yusuke Suzuki. Eventually we may want to replace the interference graph based stack allocator with one based on live-range intervals (similar to the greedy register allocator). But in the meantime, optimize the stack slot assignment algorithm from O(n²) to O(n log n). The old code tried each candidate position and re-scanned all interfering slots to verify no overlap. The new code sorts the interference list by offset and does a single sweep, pushing the candidate down past any overlapping slot. This also makes the assignment truly first-fit (closest to FP), whereas the old code iterated interference lists in arbitrary order and took the first valid position found. Improves testair performance from ~5 minutes to a few seconds because a test case (testZDefOfSpillSlotWithOffsetNeedingToBeMaterializedInARegister) had a lot of interfering tmps. Test: Source/JavaScriptCore/b3/air/testair.cpp * Source/JavaScriptCore/b3/air/testair.cpp: * Source/JavaScriptCore/b3/air/AirAllocateStackByGraphColoring.cpp: * Source/JavaScriptCore/b3/air/AirStackAllocation.cpp: (JSC::B3::Air::assign): (JSC::B3::Air::attemptAssignment): Deleted. * Source/JavaScriptCore/b3/air/AirStackAllocation.h: Canonical link: https://commits.webkit.org/309668@main
f5eac0f to
c03651a
Compare
Collaborator
|
Committed 309668@main (c03651a): https://commits.webkit.org/309668@main Reviewed commits have been landed. Closing PR #61023 and removing active labels. |
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.
🛠 ios-apple
c03651a
f5eac0f
🛠 win🧪 win-tests