perf: optimize the label representation #2448
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This slightly optimizes the label representation, by using (smaller)
PosIdxinstead ofTermPos, and a combination ofVec,SmallVec, andVector, that was found by experimentation, trying to optimize first for runtime but also for memory consumption. On the OPL benchmark the change seems to have a very small time improvement, but does at least win a few noticeable % of leaked memory.It was tempting to use only copy-on-write structures, such as a thin
Rc<[T]>orVectoreverywhere (but the latter is bigger). It turns that after measuring many label operations do succeed in taking their content mutably withcontent_make_mut(the operators pushing an element to the path, or a diagnostic for example), around a surprising 50%. On the other hand, some other mutable label operations do not currently try to take a mutable reference to the label, typically path operations. There, trying to take the label mutably shows that 0% of them succeeds... So for some reason, although I believe it's by accident, the current choices of when should we try to take unique access to a label ineval::operationsounds rather adapted. The data structure were chosen in consequence.