Repository navigation
perf(bridge-json): scan stream deltas instead of reparsing the buffer - #140
Merged
Merged
Conversation
The bridge detector reparsed the whole candidate buffer on every partial delta and called trimStart() on it each push, so a streamed write envelope cost O(n^2) on the OpenCode main thread (175 JSON.parse calls for a 9 KB write; 588 ms for a 100 KB one). Track bracket depth and string state per delta and only parse once the candidate is balanced outside a string, which any parseable envelope must be. Check a fenced candidate's info line once instead of every push. Decisions are unchanged: a differential fuzz against the previous detector over 14,400 chunkings matched exactly. 100 KB envelope: 588 ms -> 2.7 ms. Refs #139
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.
Refs #139.
The bridge detector reparsed the whole candidate buffer on every partial delta, and called
trimStart()on it every push. A streamed write envelope cost O(n²) on OpenCode's main thread.Change
Proof
JSON.parseonce (was 175). Plus a fenced-envelope streaming test.cursor-acp/auto. The model wrote a 40-function file through the bridge (call_bridge_*in the log), content intact including}]\"inside strings.bridge-jsonunit tests 55/55,opencode-loopintegration 25 pass / 1 skip. Full-suite failures andtscerrors matchmainexactly (42 and 43, none in this file).