perf(ui/state): borrow &str key in compute_grouped_rows, drop N per-connection String clones#410
Open
obchain wants to merge 1 commit into
Open
perf(ui/state): borrow &str key in compute_grouped_rows, drop N per-connection String clones#410obchain wants to merge 1 commit into
obchain wants to merge 1 commit into
Conversation
compute_grouped_rows is called every render frame when grouping is active.
It grouped connections into a HashMap<String, Vec<&Connection>>, cloning
conn.process_name once per connection to produce the owned key — N
String allocs that existed only as map keys and were dropped immediately
after building the stats.
Since connections: &'a [Connection] is already live for the lifetime 'a,
the process name can be borrowed directly:
let key = conn.process_name.as_deref().unwrap_or("<unknown>");
HashMap changes to HashMap<&'a str, Vec<&'a Connection>>. The downstream
group_stats Vec changes from Vec<(String, …)> to Vec<(&'a str, …)>.
GroupedRow still stores process_name: String, so the name.clone() calls
at row-push sites become name.to_owned() — same allocation count there,
but the N per-connection clones in the grouping loop are eliminated.
Closes domcyrus#409
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.
Closes #409
What
compute_grouped_rowsis called every render frame when grouping is active. It bucketed connections into aHashMap<String, Vec<&Connection>>, cloningconn.process_nameonce per connection to produce an ownedStringkey:With N visible connections this produced N
Stringallocations — one per connection — that existed only as map keys and were dropped after building the group stats. Theconnections: &'a [Connection]slice is already live for the full lifetime'a, so the process name can be borrowed directly:The downstream
group_statsintermediate changes fromVec<(String, …)>toVec<(&'a str, …)>.GroupedRowstill storesprocess_name: String, so thename.clone()calls at row-push sites becomename.to_owned()— the same allocation count there, but the N per-connection clones in the grouping loop are eliminated.expanded_groups.contains(&name)(wherename: String) becomesexpanded_groups.contains(name)(wherename: &str), valid viaString: Borrow<str>.Impact
Per grouped render: −N
Stringallocations where N is the number of visible connections. With 100 connections across 10 groups, that is 100 clone + 100 heap-alloc + 100 drop cycles saved every frame.Verification