[turbopack] Use an arena for `JSValue`s (#94297)
This PR takes the arena introduced in https://github.com/vercel/next.js/pull/94296 and uses it! It's large but shouldn't change functionality beyond the use of the arena. Some syntax related to pattern-matching had to change because `bumpalo`'s `Box` doesn't support the same pattern matching that the standard library's `Box` does but the code should be equivalent. `bumpalo`'s `Bump` type implements `Send` but not `Sync`, to allow us to pass a `Bump` into async-methods we wrap it in `ThreadLocal` (see https://docs.rs/thread_local/latest/thread_local/). `ThreadLocal` implements `Sync` by creating a new bumpalo allocator for each thread. We've tried to minimise the usage of `ThreadLocal` to just where it was needed. The downside of `ThreadLocal` is that we may find ourselves allocating memory for multiple arenas instead of just one. This is more time allocating if there are multiple threads compared to one shared allocation, however, it still appears to be a performance improvement over individually allocating memory for each `JSValue` --------- Co-authored-by:Benjamin Woodruff <benjamin.woodruff@vercel.com>
Showing
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Please
register
or
sign in
to comment