Repository navigation
fix(trimmer): avoid repeated serialization in batch API - #314
Merged
Merged
Conversation
liuq19
approved these changes
Nov 18, 2026
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.
Problem and root cause
TrimBatchContentWithConfigcallsrecursiveDumpafter trimming. The helper follows every include path and callsdump.DumpIDLbefore assigning the result to a filename-keyed output map. Shared include subgraphs are therefore serialized repeatedly, even though each filename appears only once in the returned map. Repeated diamonds make the serialization work grow with the number of paths rather than the number of files.The CLI deduplication in #311 covers
recurseDumpintool/trimmer/main.go; it does not cover this batch API helper.Change
Return immediately when the filename is already present in the per-invocation output map. This adds three lines to the helper and leaves the successful path/content output unchanged.
The parser caches ASTs by resolved filename, the public API checks include cycles, and each API invocation creates its own output map. The guard checks key presence, including an empty serialized file; successful serialization is still recorded before visiting includes. Errors still propagate to the caller. No process-wide cache or concurrency changes are introduced.
Reproduction
The added tests use synthetic IDLs only.
Check out this PR and run:
From a checkout of the PR commit, copy the new test into a disposable worktree at the unmodified PR base:
Before the fix this fails with
completed file was serialized again: 11 allocs. With the fix it passes with zero serialization allocations. The input is a parsed, valid root/leaf include graph with its actual completed output; no wall-clock threshold or dump hook is used.TestRecursiveDumpDedupPreservesOraclecompares every output byte with the old traversal. Its depth-14 shared DAG has 30 unique files and causes 49,151 dump calls in the old traversal. The final maps are identical after deduplication. Other tests cover empty output, independent invocations, and parallel calls using independent ASTs/maps.Validation
Base:
6e9c23bcd91ac44fb9bd84f958b62d49ab3ec7b9(main; the repository currently exposes nodevelopbranch).go test ./tool/trimmer/...passes.go test -race ./...passes.go vet -stdmethods=false ./...passes (the repository Makefile uses the same vet flag).fastgo,fieldmask,options(102 cases), andunknown_fields. The last suite was rerun separately after allowing its missing public dependency into the Go cache; the first attempt stopped on a local cache-lock permission error.gofmtandgit diff --checkpass.The parallel test covers this helper with independent ASTs/maps; it does not claim that the entire trimming API is safe for concurrent use.
Downstream adoption
Consumers need to update the
github.com/cloudwego/thriftgomodule dependency to a resolvable upstream commit/version containing this fix and record the resolved version and checksums. Updating the standalonethriftgoexecutable does not update an application that imports the batch trimming API. No downstream configuration, deployment, merge, or release is part of this PR.The current PR head
a37e41fbe7b77e71f679e0bde28f526a2c221425resolves through GoProxy asv0.4.6-0.20261118083004-a37e41fbe7b7. The downloaded source and module files match the submitted commit. This is an unmerged PR commit, not a release; downstream dependency upgrades still need their own review and integration checks.