ls: More performance optimizations #7813
Merged
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.
Gets closer to GNU
ls
, ~8% gain vs current main.ls: Optimize time formatting
Instead of recreating the formatter over and over again, keep
it pre-parsed in a variable in TimeStyler class.
Also, avoid calling
now
over and over again, that's also slow.Improves performance by about 6%.
ls: display_uname/group: Return a reference
Cache even numerical strings (numeric_uid_gid) in the HashMap,
this makes very little difference performance wise.
However, this allows us to return a reference to a String instead
of making a clone.
Saves about 2-3% on
ls -lR /var/lib .git
(andls -lRn
).Also, add a note that HashMap might not be the most optimal choice.
ls: ListState: Add uid/gid cache to the structure
Easier to reason about than the LazyLock/Mutex encapsulated
static variables.
Performance difference is not measurable, but this drops uneeded
Mutex lock/unlock that were seen in samply output.
ls: Create a ListState struct to maintain state
We put the out writer and style manager in there, for now.
Reduces the number of parameters to pass around, and we'll add
more useful things in there.
Little to no performance difference.