Repository navigation
perf(sources,util): optimize row serialization and avoid speculative json parsing - #3660
Deeven-Seru wants to merge 2 commits into
Conversation
d03f541 to
6ab36d0
Compare
There was a problem hiding this comment.
Code Review
This pull request refactors the codebase by replacing the legacy toolset and promptset concepts with a unified group structure, introducing a new internal/group package and updating configuration parsing, resource management, and CLI commands accordingly. It also includes performance optimizations for SQLite JSON detection and ordered map JSON marshaling. Feedback suggests splitting the large-scale refactoring and performance optimizations into separate pull requests to reduce risk, and correcting several test failure messages that still refer to 'toolsets' instead of 'groups' for consistency.
I am having trouble creating individual review comments. Click here to see my feedback.
cmd/internal/config.go (39-41)
This pull request mixes a large-scale refactoring (renaming toolset to group) with performance optimizations. According to our best practices, refactoring should be kept in separate PRs from functional changes to make reviews easier and reduce risk. Please consider splitting such changes into separate PRs in the future.
cmd/internal/config_test.go (868)
The test failure message refers to "toolsets" but the code is checking configFile.Groups. This could be confusing if the test fails. Please update the message to refer to "groups" for consistency.
This issue also appears on lines 1119, 1461, and 2208. Please correct them as well.
t.Fatalf("incorrect groups parse: diff %v", diff)
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces performance optimizations for JSON handling, including a fast-path check IsProbablyJSON to avoid unnecessary json.Unmarshal calls on non-JSON strings in SQLite source processing, and refactoring orderedmap.MarshalJSON to use json.NewEncoder with byte-level buffer writes. The reviewer pointed out that the current implementation of IsProbablyJSON is too permissive because it triggers on common starting letters like 't', 'f', and 'n', which can degrade performance on normal text datasets, and provided a more robust implementation to check matching brackets, quotes, and strict boolean/null/number patterns.
6ab36d0 to
bcf2fe6
Compare
bcf2fe6 to
71e9895
Compare
|
Hi @Yuan325, thanks for the review!
|
## Description Fixes #4430. SQLite JSON results containing 64-bit IDs are rounded on the server: `json_object('id', 9007199254740993)` reaches the tool response as `9007199254740992`. Keep valid JSON as `json.RawMessage` instead of decoding numbers through `any`/`float64`. Both SQLite tools share this path; ordinary text retains its existing fallback. Related #3660 optimizes JSON detection and row serialization; it does not preserve numeric precision. The real SQLite unit and public HTTP regression both fail on `06ea49d` with the rounded ID and pass after the fix. SQLite source/tool unit packages, all four `TestSQLiteExecuteSqlTool` cases, source-package vet, scoped golangci-lint 2.15.0 and goimports formatting pass. Go 1.27.3; module files unchanged. ## PR Checklist - [x] Reviewed CONTRIBUTING.md. - [x] Opened #4430 before implementing the fix; a local diagnostic case first verified the report. - [x] Reviewed the entire diff, including an independent agent review. - [x] Relevant tests and linter pass. - [ ] Code coverage does not decrease (numeric coverage comparison not run locally). - [x] Documentation assessed: this corrects existing JSON result behavior; no configuration or documentation change is needed. - [x] Breaking-change assessment completed; no API signature changes. <details><summary>Validation scope</summary> ```sh go test -mod=readonly -p=2 ./internal/sources/sqlite -count=1 go test -mod=readonly -p=2 ./internal/tools/sqlite/... -count=1 go test -mod=readonly -p=2 ./tests/sqlite \ -run '^TestSQLiteExecuteSqlTool$' -count=1 -v -timeout=10m go vet -mod=readonly -p=2 ./internal/sources/sqlite golangci-lint run --timeout 10m ./internal/sources/sqlite/... \ ./internal/tools/sqlite/... ./tests/sqlite/... ``` The existing HTTP fixture was temporarily pointed at a free local port because 5000 was occupied; the port changes were restored. The regression exercises the real temporary database and tool endpoint. No external database or model service was used. The full repository integration matrix and coverage comparison were not run. </details> Co-authored-by: Anubhav Dhawan <[email protected]>
Description
Optimizes the core performance bottlenecks in the MCP toolbox during row serialization.
util.IsProbablyJSON), reducing OOM risks and CPU overhead on large text datasets.orderedmap.Row.MarshalJSONto stream output linearly into a single bufferedjson.Encoder, resulting in a ~2.5x speedup during row serialization.PR Checklist
!if this involves a breaking changeIssue Reference
Fixes #3659 🦕