perf(ui/state): cache lowercase sort key for grouped-process ordering#353
Open
obchain wants to merge 1 commit into
Open
perf(ui/state): cache lowercase sort key for grouped-process ordering#353obchain wants to merge 1 commit into
obchain wants to merge 1 commit into
Conversation
`compute_grouped_rows` sorted process groups with: group_stats.sort_by_key(|a| a.0.to_lowercase()); `slice::sort_by_key` does not cache the extracted key — it calls the closure on every comparison, so a merge sort invokes it O(N log N) times. Each call allocates a fresh lowercase `String`, meaning sorting N process groups performs ~N·log₂(N) heap allocations where N would do. `compute_grouped_rows` runs on every regroup in the Overview grouped view, so this recurs on the update path, not just once. Switch to `slice::sort_by_cached_key`, which calls the key function exactly once per element, caches the results, and sorts those. Same key, same ordering — strictly fewer allocations. For 64 process groups that's 64 lowercase Strings per regroup instead of ~384. No behavior change; full lib test suite (379) stays green. Closes domcyrus#352
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
compute_grouped_rowssorted process groups with:slice::sort_by_keydoes not cache the extracted key — it calls the closure on every comparison, so a merge sort invokes it O(N log N) times. Each call allocates a fresh lowercaseString, so sorting N process groups performs ~N·log₂(N) heap allocations where N would do.compute_grouped_rowsruns on every regroup in the Overview grouped view (togglinga, plus refreshes while grouping is active), so this recurs on the update path, not just once.Switch to
slice::sort_by_cached_key, which calls the key function exactly once per element, caches the results, and sorts those. Same key, same ordering — strictly fewer allocations. For 64 process groups that's 64 lowercaseStrings per regroup instead of ~384.Closes #352.
Behavior
No change — identical sort key and comparison. Verified by:
Test plan
cargo test --libcargo fmt --checkcargo clippy --all-targets -- -D warnings