[Repo Assist] perf: eliminate unnecessary List(T) allocations in DisplayText and GetSessionListInternal#156
Closed
github-actions[bot] wants to merge 1 commit intomasterfrom
Conversation
SessionInfo.DisplayText was allocating new List<string> + internal backing array on every call (happens every UI refresh per session). Replace with a simple tuple-switch over at most two optional segments so only the final interpolated string is allocated. GetSessionListInternal was constructing a List<SessionInfo> from the dictionary values and then calling .ToArray(), paying two heap allocations per session-list snapshot. Replace with a single new SessionInfo[_sessions.Count] + Values.CopyTo + Array.Sort so only one array is allocated and the sort is performed in-place. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
9 tasks
Collaborator
|
Thanks for the cleanup here — the idea makes sense, but we’re going to pass on this one for now. The current code is working today, and this is mostly a micro-optimization rather than a bug fix. We’d rather avoid extra churn in the session display/list snapshot path unless we’re addressing a larger underlying issue at the same time. |
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.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Two small hot-path allocations eliminated:
SessionInfo.DisplayTextandGetSessionListInternal.1.
SessionInfo.DisplayText— avoidList(string)per UI renderProblem:
DisplayTextbuilds a 1–3 element list then callsstring.Join, allocating both aList(string)and its backingstring[]on every call. This property is called every UI refresh for every visible session.Fix: Replace with a tuple switch over the two optional segments (
midandend); only the final interpolated string is allocated, same as before.2.
GetSessionListInternal— avoid double-copy on session-list snapshotProblem: Every session-list update called
new List(SessionInfo)(_sessions.Values)(copy 1) then.ToArray()(copy 2), paying two heap allocations per snapshot.Fix: Allocate one
SessionInfo[count]array,CopyTothe dictionary values directly into it, sort in-place withArray.Sortand astaticlambda.Trade-offs
SessionInfoTestsandGetSessionList_SortsMainSessionFirsttests pass unchanged.staticlambda inArray.Sortavoids the delegate allocation each time (compiler caches it).Test Status