Visitar URL original
[WTF] Reduce stack use and code size of Vector append slow paths by ddkilzer · Pull Request #76313 · WebKit/WebKit · GitHub
Skip to content

[WTF] Reduce stack use and code size of Vector append slow paths - #76313

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
ddkilzer:eng/Reduce-stack-use-and-code-size-of-Vector-append-slow-paths
Oct 9, 2026
Merged

webkit-commit-queue merged 1 commit into
WebKit:mainfrom
ddkilzer:eng/Reduce-stack-use-and-code-size-of-Vector-append-slow-paths

Conversation

@ddkilzer

@ddkilzer ddkilzer commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

22f00b3

[WTF] Reduce stack use and code size of Vector append slow paths
<https://bugs.webkit.org/show_bug.cgi?id=326804>
<rdar://189511255>

Reviewed by Marcus Plutowski.

Pass small trivially copyable arguments by value to the out-of-line slow
paths of `Vector::append()` and `Vector::constructAndAppend()`.  The
`append()` slow path takes the argument's address so `expandCapacity()`
can rebase it if it points into the buffer being reallocated, and taking
that address forces callers to keep the value in a stack slot, even for
an `int` or a pointer.  Copying such a value into a parameter before the
buffer grows makes the rebase unnecessary.

Also move the `constructAndAppend()` slow path out of line, as
201368@main did for the `append()` reallocation in `expandCapacity()`.
Without `NEVER_INLINE`, clang inlines its reallocation sequence into
many call sites, which grows code at each `constructAndAppend()` caller.

Make `constructAndAppendSlowCase()` `ALWAYS_INLINE` into the by-value
wrapper rather than `NEVER_INLINE` itself, since its by-reference
parameters would make each caller copy a small argument from a register
to a stack slot just to pass the slot's address.

In a macOS release build, this shrinks `__text` by about 104 KB (0.1%)
across JavaScriptCore, WebCore, WebKit, WebKitLegacy, and WebGPU, and
the sum of their stack frame sizes by about 9.7 KB, mostly in
JavaScriptCore and WebCore.  Speedometer 3 is neutral.

No new tests since no change in behavior.

* Source/WTF/wtf/Vector.h:
(WTF::Vector::append):
(WTF::Vector::constructAndAppend):
(WTF::Vector::appendSlowCaseByValue): Add.
(WTF::Vector::constructAndAppendSlowCaseOutOfLine): Add.
(WTF::Vector::constructAndAppendSlowCase):

Canonical link: https://commits.webkit.org/323213@main

4e3fbfe

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ❌ 🛠 ios-apple
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests ✅ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe ✅ 🛠 vision-apple
✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-debug ✅ 🧪 jsc-wpe
✅ 🧪 jsc-x86-64 ✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk3-gcc
✅ 🛠 🧪 jsc-debug-arm64 ✅ 🛠 ios-safer-cpp ✅ 🧪 mac-AS-debug-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 gtk-wk2
✅ 🛠 🧪 merge ✅ 🛠 vision-sim ✅ 🧪 mac-intel-wk2 ✅ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🛠 mac-safer-cpp ✅ 🛠 playstation
✅ 🛠 tv ✅ 🧪 mac-site-isolation
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@ddkilzer
ddkilzer requested a review from a team as a code owner October 8, 2026 13:18
@ddkilzer ddkilzer self-assigned this Oct 8, 2026
@ddkilzer
ddkilzer force-pushed the eng/Reduce-stack-use-and-code-size-of-Vector-append-slow-paths branch from 2b915f8 to 4e3fbfe Compare October 8, 2026 18:12
@ddkilzer ddkilzer added the safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks label Oct 8, 2026
@webkit-ews-buildbot webkit-ews-buildbot added merge-queue Applied to send a pull request to merge-queue and removed safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks labels Oct 9, 2026
@webkit-ews-buildbot

Copy link
Copy Markdown
Collaborator

Safe-Merge-Queue: Build #107037.

<https://bugs.webkit.org/show_bug.cgi?id=326804>
<rdar://189511255>

Reviewed by Marcus Plutowski.

Pass small trivially copyable arguments by value to the out-of-line slow
paths of `Vector::append()` and `Vector::constructAndAppend()`.  The
`append()` slow path takes the argument's address so `expandCapacity()`
can rebase it if it points into the buffer being reallocated, and taking
that address forces callers to keep the value in a stack slot, even for
an `int` or a pointer.  Copying such a value into a parameter before the
buffer grows makes the rebase unnecessary.

Also move the `constructAndAppend()` slow path out of line, as
201368@main did for the `append()` reallocation in `expandCapacity()`.
Without `NEVER_INLINE`, clang inlines its reallocation sequence into
many call sites, which grows code at each `constructAndAppend()` caller.

Make `constructAndAppendSlowCase()` `ALWAYS_INLINE` into the by-value
wrapper rather than `NEVER_INLINE` itself, since its by-reference
parameters would make each caller copy a small argument from a register
to a stack slot just to pass the slot's address.

In a macOS release build, this shrinks `__text` by about 104 KB (0.1%)
across JavaScriptCore, WebCore, WebKit, WebKitLegacy, and WebGPU, and
the sum of their stack frame sizes by about 9.7 KB, mostly in
JavaScriptCore and WebCore.  Speedometer 3 is neutral.

No new tests since no change in behavior.

* Source/WTF/wtf/Vector.h:
(WTF::Vector::append):
(WTF::Vector::constructAndAppend):
(WTF::Vector::appendSlowCaseByValue): Add.
(WTF::Vector::constructAndAppendSlowCaseOutOfLine): Add.
(WTF::Vector::constructAndAppendSlowCase):

Canonical link: https://commits.webkit.org/323213@main
@webkit-commit-queue
webkit-commit-queue force-pushed the eng/Reduce-stack-use-and-code-size-of-Vector-append-slow-paths branch from 4e3fbfe to 22f00b3 Compare October 9, 2026 10:42
@webkit-commit-queue

Copy link
Copy Markdown
Collaborator

Committed 323213@main (22f00b3): https://commits.webkit.org/323213@main

Reviewed commits have been landed. Closing PR #76313 and removing active labels.

@webkit-commit-queue
webkit-commit-queue merged commit 22f00b3 into WebKit:main Oct 9, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Oct 9, 2026
@ddkilzer
ddkilzer deleted the eng/Reduce-stack-use-and-code-size-of-Vector-append-slow-paths branch October 9, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants