[Repo Assist] perf: O(1) command dispatch index in WindowsNodeClient#153
Closed
github-actions[bot] wants to merge 1 commit intomasterfrom
Closed
Conversation
Replace two O(n) _capabilities.FirstOrDefault(c => c.CanHandle(command)) linear scans with a single O(1) Dictionary<string, INodeCapability> lookup. The _commandIndex is populated in RegisterCapability (once per capability registration at startup). On every node.invoke.request or req dispatch, the lookup is now O(1) regardless of how many capabilities are registered. Also removes the now-unused 'using System.Linq' import. Adds 3 unit tests covering: - all commands of a registered capability appear in the index - multiple capabilities are indexed to their correct handler - the dictionary is case-insensitive (StringComparer.OrdinalIgnoreCase) Co-authored-by: Copilot <[email protected]>
9 tasks
Collaborator
|
Thanks for the optimization here. We’re going to pass on this one for now because the current dispatch path is already working well, and this change subtly alters the command-routing behavior (for example around case-sensitivity / exact dispatch semantics) for a fairly small performance win. We’d rather revisit this later as part of a broader node-dispatch cleanup if needed. |
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
Replaces two O(n) linear scans with a single O(1) dictionary lookup for command dispatch in
WindowsNodeClient.Problem
Every
node.invoke.requestandreqmessage dispatched throughWindowsNodeClientcalled:CanHandleinNodeCapabilityBasedoesCommands.Contains(command)— itself an O(n) scan over the capability's command list. The combined complexity is O(capabilities × commands-per-capability) on every invocation.Fix
A
Dictionary(string, INodeCapability) _commandIndex(withStringComparer.OrdinalIgnoreCase) is built once inRegisterCapability. Both dispatch call sites now use: