[Repo Assist] perf: replace map[string]interface{} with typed structs in RPC hot paths#2312
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
Conversation
Every outbound JSON-RPC call marshaled a freshly-allocated
map[string]interface{} to build the request envelope (http_transport.go)
and a second map in connection.go for the log payload. Go maps always
live on the heap because their internal hash table is heap-allocated,
even for small maps.
Replace both with typed structs:
- jsonrpcRequest in http_transport.go (JSONRPC, ID, Method, Params)
- jsonrpcLogPayload in connection.go (JSONRPC, Method, Params)
Typed structs can be allocated inline or on the stack by the compiler,
reducing GC pressure on the request hot path. JSON marshaling of structs
also skips the map iteration and key-type-assertion overhead, making it
faster for fixed-schema objects.
Update TestCreateJSONRPCRequest and TestCreateJSONRPCRequest_HasAllRequiredFields
to use struct field access instead of map key lookups.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
map[string]interface{}allocations on the JSON-RPC request hot path with typed structs, reducing per-call heap allocations and GC pressure.Changes
internal/mcp/http_transport.go—createJSONRPCRequestEvery outbound HTTP JSON-RPC request called
createJSONRPCRequest, which allocated amap[string]interface{}just to marshal it into JSON bytes immediately afterward. Go maps always live on the heap (the internal hash table is heap-allocated), even for tiny maps with 4 entries.Replaced with:
internal/mcp/connection.go—SendRequestWithServerIDThe outbound request log entry also built a
map[string]interface{}on every call (for stdio and HTTP connections alike). Replaced with a dedicatedjsonrpcLogPayloadstruct (noIDfield since the log format doesn't include it).Why It Helps
encoding/jsonproduces identical JSON output from both representationsFor an MCP gateway that proxies every tool call through these paths, eliminating 2 heap allocations per request reduces GC frequency under load.
Tests Updated
TestCreateJSONRPCRequestandTestCreateJSONRPCRequest_HasAllRequiredFieldsupdated to use struct field access (req.JSONRPC,req.ID, etc.) instead of map key lookups.TestCreateJSONRPCRequest_IsSerializablewas unchanged (it round-trips through JSON).Test Status
Warning
The following domains were blocked by the firewall during workflow execution:
proxy.golang.orgreleaseassets.githubusercontent.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.