perf: optimize allocation strategies of output/parser/event#22078
perf: optimize allocation strategies of output/parser/event#22078landaire wants to merge 1 commit intorust-lang:masterfrom
Conversation
|
First, do you have any benchmark proving that parsing indeed became faster with these changes? Second, about shrinking I have no problems merging the |
|
@ChayimFriedman2 sorry, not sure I follow on this:
Maybe the
While it might be short-living, it has a pretty major impact on peak memory usage by RA which I imagine does indeed have cascading effects. Especially for individuals on more resource-constrained systems (Apple is once again shipping MacBooks with 8GiB of RAM after all). |
|
It shouldn't have an impact even on peak memory usage because we aren't parsing many files concurrently, at most the number of cores. Unless profiling will show otherwise, of course. |
|
Ah I see what you're saying. Yeah I think the |
|
The changes to |
|
Not when it is resized but when it's dropped, still this can be beneficial. |
This change does a couple of different, but semi-related things. Happy to split this change up into multiple PRs if desired to keep these in isolation.
Note: This is my first contribution to rust-analyzer and also was mostly done by Claude. All tests pass and from my human analysis of the change things look good. This description written by a human -- tables assembled by Claude.
Memory profiling done on an M5 MacBook Pro.
EventSize ShrinkageThrough memory profiling, it was realized that the
parser::Parser, a large consumer of memory, retains manyparser::Events that are forced to be a 24-byte structure, mostly because of theErrorvariant which held aString. Claude reworked this pattern to instead use an internalVec<String>and theErrorvariant holds a 32-bit index into this vector.Claude also noted that
forward_parentfield inEvent::Startis always non-zero and can be changed to aNonZeroU32for further memory savings.Output.eventoptimizationThe
Output.eventvec uses a naivepushstrategy for allocation, but can be pre-allocated to avoid unnecessary memory growth from the vector's reallocation strategy.Overall results: