-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid copies when freezing and writing layers to disk #657
Comments
Yeah, copying the BTreeMaps is pretty expensive. Looking 'perf' profile, it incurs all kinds of overheads that add up:
|
I actually spent some time exploring this yesterday, and came up with this pretty simple optimization: https://github.com/zenithdb/zenith/tree/reduce-treemap-copying. It eliminates one of the expensive BTreeMap copies, when new DeltaLayer is created. Instead of passing the page versions as a BTreeMap, the DeltaLayer::create function now takes an Iterator. It needs some polishing and comments, but it's a pretty small change with big impact. That doesn't eliminate all the BTreeMap copies and overhead, though, there's more that could be done. |
Some other things I've been exploring and thinking, but don't have a patch yet:
And:
|
Just a few notes:
If I understand it correctly tracking is not directly connected to arena allocator, so it can be any allocator with internal tracking. And it is simple to build our own one which wraps default allocator and records allocations (or take something from crates.io).
Even on nightly custom allocator for BTreeMap is not available yet, see rust-lang/wg-allocators#7 Also see this discord thread: https://discord.com/channels/869525774699462656/890916952489484298/890916955488419900 |
Also for a fixed size data like pages we can leverage slab allocation (for example https://github.com/tokio-rs/slab) |
This hasn't been a signficant performance issue for a while now. All the ideas for improvements listed here still probably make sense, but the first thing would be to do some profiling to see where exactly the CPU time is spent nowadays, and decide what to do based on that. Closing. |
We copy the segsizes and page_versions BTreeMaps during both of these processes.
Instead, maybe we can move these structs into an Arc, and share the Arc + valid range of LSN to users of the data
The text was updated successfully, but these errors were encountered: