[Repo Assist] perf: reduce allocations in hot paths (preview string, cache key, schema logging)#2308
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
Conversation
- middleware/jqschema: avoid converting the full payload []byte to string
when only the first PayloadPreviewSize (500) chars are needed for the
preview field; for a 10 MB payload this eliminates a ~10 MB string
allocation on every large-payload tool call
- middleware/jqschema: remove temporary json.Marshal(schemaObj) that was
used solely to compute a byte count for a debug log line; schema
marshaling happens again moments later in the final response, so this
was an extra allocation with no observable benefit
- server/routed: replace fmt.Sprintf('%s/%s', ...) with simple string
concatenation for the filteredServerCache key; no format verbs are
needed and string-concat avoids the reflection overhead of fmt.Sprintf
on every tool call in routed mode
- server/unified: pre-allocate toolNames slice with known capacity
(len(listResult.Tools)) to avoid repeated growths during tool
registration at startup
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
7 tasks
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
Three targeted allocation reductions found during profiling of the hot paths in
middleware/jqschema.go,server/routed.go, andserver/unified.go. No behaviour changes — all existing tests continue to pass.1.
middleware/jqschema: avoid full payload→string conversion for preview (most impactful)Before
After
For a 10 MB tool response, the old code allocated a ~10 MB
stringjust to slice out the first 500 characters. The new code converts only the needed bytes. On every large-payload tool call this eliminates a heap allocation proportional to the full response size.2.
middleware/jqschema: remove temporaryjson.Marshal(schemaObj)used only for a debug logBefore
After
schemaObjis marshaled again seconds later to build the final response. This intermediate marshal was purely for a debug log byte-count and served no other purpose — it was an unconditional allocation on the large-payload path.3.
server/routed:fmt.Sprintf→ string concat for cache keyBefore
After
fmt.Sprintfuses reflection and a format parser even for trivial patterns. String concatenation with+is direct. This runs on every tool call in routed mode when checking thefilteredServerCache.4.
server/unified: pre-allocatetoolNamesslice at startupBefore
After
Avoids repeated slice growths during tool registration. The number of tools is known at this point. This only runs at startup, so impact is minimal, but it is the idiomatic Go pattern.
Test Status
Closes no specific issue — identified by Repo Assist during a performance sweep of hot-path allocations.
Warning
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.