-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
When I wrote #1996, I implemented this by pre-computing some values beforehand to speed up comparisons later. There are other cases where we rely on pre-computed values. While this can result in a speed improvement, it has the big disadvantage of increasing our overall memory usage. The way it is currently implemented also means that we pay a constant tax even for lines/files that would not need precomputed values. That said, I think we should not rely on precomputed values for our comparisons. We can later experiment with adding them back for cases where they bring significant improvements without impacting other use-cases.
Places where pre-computed values are used:
- numeric string comparisons (
-hand-n): The current algorithm is expecting that pre-computed values are cached. To achieve similar performance without caching, it needs to be rewritten.Expected performance impact: Small performance regression, improvements for other use-cases and already sorted files. -
general numeric comparisons: Parsed f64 values are cached. Reverting this should be relatively straight-forward. Should only be a minor performance regression.See sort: Reduce memory overhead #2134 (comment), this may not be as useful as I initially thought. - transforms: (-f, -d, -i, -b) could be implemented with a custom string comparison algorithm. Allocating new strings for every comparison could have a noticeable performance impact: sort: add some custom string comparisons #2144
- fields: (-k) This could potentially benefit from caching, but maybe in a limited form? I have to investigate what the performance penalty for tokenizing each time would be.
Generally the goal is to
- reduce memory usage: Currently every line gets its own
Linestruct that is 96 bytes big. This is due to the precomputed values for numeric string comparison and indices for field support we have to reserve space for. The goal is to reduce this to just a&str, i.e. 16 bytes. - speed cases up that do not need pre-computed values anyways.
- observe the performance impact and at a later point add mitigations for them.
cc @electricboogie does roughly sound ok to you? If so, I'll start implementing this the next days.