Skip to content

StringImpl refcounting should be atomic - #1713

Open
justinmichaud wants to merge 1 commit into
WebPlatformForEmbedded:wpe-2.46from
justinmichaud:cherry-pick-atomic-ref
Open

StringImpl refcounting should be atomic#1713
justinmichaud wants to merge 1 commit into
WebPlatformForEmbedded:wpe-2.46from
justinmichaud:cherry-pick-atomic-ref

Conversation

@justinmichaud

@justinmichaud justinmichaud commented Aug 14, 2026

Copy link
Copy Markdown

There are a number of crashes related to this missing backport on 2.38. This leads to crashes in ~StringImpl, bmalloc, and a few other unexpected places in JSC coming from shared stringimpls in random places like gstreamer.

This backport is missing lots of optimizations from the ToT verision to reduce risk, so it is probably a larger perf regression. These should just avoid decreasing ref churn, not affect correctness.
a63911f

Build-Tests Layout-Tests
❌ 🛠 wpe-246-amd64-build ❌ 🧪 wpe-246-amd64-layout
❌ 🛠 wpe-246-arm32-build ❌ 🧪 wpe-246-arm32-layout

@justinmichaud
justinmichaud force-pushed the cherry-pick-atomic-ref branch 2 times, most recently from f512a9d to 83732ab Compare August 14, 2026 20:17
https://bugs.webkit.org/show_bug.cgi?id=289962
rdar://147313174

Backport notes:
I removed some optimizations; ref churn is not great, but still correct.

Original notes:

Reviewed by Antti Koivisto, Yusuke Suzuki, Chris Dumez, and Keith Miller.

This patch takes the first step to making WTF::String thread-safe: Making
m_refcount increment and decrement atomic. (Hash, flags, and the AtomString
table are not yet atomic. I plan to address those in my next patch.)

The direct code change is pretty small, but it measured as a performance
regression. So most of this code is optimization. I got rid of about 1/3 of
WTF::StringImpl refcounts on Speedometer and about 1/2 on JetStream.

ARM has a special ldadd instruction for fast atomics. Net net, it measures as
about 1.5X slower than just add. That's pretty good! But it still required
some optimizations to be affordable. Intel atomics are much slower, so it took
far more optimizations to get Intel across the finish line.

A/B testers suggest that we might still have a < 0.5% JetStream regression on
Intel. I checked in with Yusuke, Keith, and Maciej, and we can move forward
because we have a large total JetStream speedup on Intel this year, so customers
on older hardware will still see a net speedup when they get new software.
@justinmichaud
justinmichaud force-pushed the cherry-pick-atomic-ref branch from 83732ab to a63911f Compare August 14, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants