-
Notifications
You must be signed in to change notification settings - Fork 397
Refact: pre-allocate memory for memory-efficiency #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis update introduces minor optimizations and code corrections in the server implementation. In the main server logic, method calls are corrected to use the appropriate exported function names, and map initializations are updated to include capacity hints for improved allocation efficiency. Additionally, the test server setup is streamlined by consolidating option application into a single function call, removing redundant code. No changes are made to public interfaces or control flow. Changes
Possibly related PRs
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
server/server.go
(3 hunks)server/sse.go
(1 hunks)
🔇 Additional comments (3)
server/sse.go (1)
182-182
: Nice simplification of the codeThis change efficiently utilizes the variadic parameter passing in Go. Instead of creating the server first and then applying options in a loop, you're passing all options directly to
NewSSEServer
, which already handles the application of options internally. This reduces code duplication and improves readability.server/server.go (2)
495-495
: Optimized map initialization with capacity hintGood optimization to pre-allocate the map with the exact capacity needed. When we know the final size of a map in advance, providing this capacity hint avoids incremental memory reallocations during map growth, improving memory efficiency.
717-717
: Optimized map initialization with capacity hintSimilar to the previous optimization, pre-allocating the Arguments map with the known size of matchedVars improves memory efficiency by avoiding incremental reallocations during map population.
@@ -429,7 +429,7 @@ func (s *MCPServer) RemoveResource(uri string) { | |||
|
|||
// Send notification to all initialized sessions if listChanged capability is enabled | |||
if s.capabilities.resources != nil && s.capabilities.resources.listChanged { | |||
s.sendNotificationToAllClients("resources/list_changed", nil) | |||
s.SendNotificationToAllClients("resources/list_changed", nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed method capitalization bug
This corrects a critical bug where the lowercase method name sendNotificationToAllClients
was being called, but only the capitalized SendNotificationToAllClients
method exists (defined on line 217). In Go, method names are case-sensitive, so this change ensures the correct method is called.
* pre-allocate memory for memory efficiency * fix bug for calling func SendNotificationToAllClients
s.sendNotificationToAllClients
---->s.SendNotificationToAllClients
, the former of which is not defined forMCPServer
map
whose final capacity could be known at the beginning for memory efficiencySummary by CodeRabbit
No changes to user-facing features or functionality.