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
perf(codegen): reduce allocations in SourcemapBuilder (#13677)
Follow-on after #13670.
That PR made 2 changes:
1. Pre-allocating capacity in `columns` `Vec`.
2. `mem::take`-ing `columns` for each line, rather than re-using it.
In my opinion, the 1st change is good, but the 2nd is not.
Revert the usage of `mem::take`, and add a comment explaining why the `.clone()` is not as bad as it looks!
Before this PR: `columns` will likely have spare capacity, so `mem::take(&mut columns).into_boxed_slice()` will perform a reallocation to drop the excess capacity, and then `columns.reserve(256)` performs a 2nd allocation.
Approach after this PR:
1. `columns.clone().into_boxed_slice()` performs 1 allocation, and copies the data from `columns` into this new allocation. `columns.clear()` does not perform any reallocation, and is a very cheap operation.
2. `columns` `Vec` is reused over and over, and will grow adaptively depending on how heavy the file's use of unicode chars is, rather than always going back to estimated max capacity of 256.
Benchmarks show a very small positive difference.
0 commit comments