You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[turbopack] mark rcstr! allocated Rcstr values as 'static' and stop refcounting them (#81994)
# Optimize RcStr with Static Atom Support
## What?
For RcStr values allocated by the `rcstr!` macro we shouldn't bother reference counting them since they are pinned to a static memory location already. This uses a spare tag bit `0b10` to mark such strings as 'static' which allows us to to optimize the `clone` and `drop`. The only practical cost is an additional constant bit mask when reading the value as a pointer.
Also:
* add a fast path for `PartialEq<RcStr>` to handle identical values, this is useful especially for inline RcStr values but adds a fast path for refcounted strings as well.
* compute the `hash` of `rcstr!` parameters at compile time by `const`-ifying the hash fn
* allocate static storage for the `PrecomputeHash` struct
- ideally we would 'const' allocate it, but `String` isn't const compatible. We could maybe use `String::from_raw_parts` but it would depend on too many implementation details. The real solution here is probably to change the definition of PrehashedString to hold an Either or a Cow? not sure if that is worth it.
## Why?
Atomic ref counting is cheap but not free, we have a large number of `rcstr!` allocated strings and so it is pure overhead to spend any time refcounting them when the count will never hit zero.
See the upstack PR for some performance measurements on vercel-site
0 commit comments