Skip to content

Commit 850ce6e

Browse files
jensneuseclaude
andauthored
feat(resolve): update astjson to arena-safe API, remove redundant copies (#1400)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Bumped CI lint action version and adjusted module dependencies (added/upgraded entries). * **Refactor** * Improved internal JSON/value memory management to use arena-scoped lifetimes for safer GC behavior. * Minor printing/formatting tweaks in execution logging. * **Tests** * Added a comprehensive GC-stress test suite validating arena safety and resolver behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Updates `github.com/wundergraph/astjson` to a version that copies input bytes onto the arena internally, eliminating the need for manual pre-copy steps in `loader.go`. Removes the `parseStringOnArena` helper (16 call sites) and `stringValueOnArena` helper (7 call sites), and drops the inline byte copy in `mergeResult`. Updates all call sites for the revised astjson API (`SetValue`, `AppendToArray`, `SetNull`, `AppendArrayItems`, `TrueValue` now take an arena argument). Adds 47 GC safety tests covering all astjson-touching codepaths in `loader.go` and `resolvable.go`, including status-code error paths, error filtering, resolvable scalar walks, and type mismatches. ## Checklist - [ ] I have discussed my proposed changes in an issue and have received approval to proceed. - [x] I have followed the coding standards of the project. - [x] Tests or benchmarks have been added or updated. --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f811b29 commit 850ce6e

11 files changed

Lines changed: 1343 additions & 112 deletions

File tree

.github/workflows/execution.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
uses: golangci/golangci-lint-action@v8.0.0
6060
with:
6161
working-directory: execution
62-
version: v2.4.0
62+
version: v2.10.1
6363
args: --timeout=3m
6464
ci:
6565
name: CI Success

.github/workflows/v2.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
uses: golangci/golangci-lint-action@v8.0.0
6464
with:
6565
working-directory: v2
66-
version: v2.4.0
66+
version: v2.10.1
6767
args: --timeout=3m
6868
ci:
6969
name: CI Success

go.work

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
go 1.25
22

3-
toolchain go1.25.1
4-
53
use (
64
examples/federation
75
execution

v2/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ require (
2020
github.com/jensneuse/diffview v1.0.0
2121
github.com/kingledion/go-tools v0.6.0
2222
github.com/kylelemons/godebug v1.1.0
23+
github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d
2324
github.com/pkg/errors v0.9.1
2425
github.com/r3labs/sse/v2 v2.8.1
2526
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
@@ -28,7 +29,7 @@ require (
2829
github.com/tidwall/gjson v1.17.0
2930
github.com/tidwall/sjson v1.0.4
3031
github.com/vektah/gqlparser/v2 v2.5.30
31-
github.com/wundergraph/astjson v1.0.0
32+
github.com/wundergraph/astjson v1.1.0
3233
github.com/wundergraph/go-arena v1.1.0
3334
go.uber.org/atomic v1.11.0
3435
go.uber.org/goleak v1.3.0
@@ -57,7 +58,6 @@ require (
5758
github.com/mattn/go-colorable v0.1.14 // indirect
5859
github.com/mattn/go-isatty v0.0.20 // indirect
5960
github.com/oklog/run v1.0.0 // indirect
60-
github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d // indirect
6161
github.com/pmezard/go-difflib v1.0.0 // indirect
6262
github.com/rogpeppe/go-internal v1.13.1 // indirect
6363
github.com/russross/blackfriday/v2 v2.1.0 // indirect

v2/go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,8 @@ github.com/urfave/cli/v2 v2.27.7 h1:bH59vdhbjLv3LAvIu6gd0usJHgoTTPhCFib8qqOwXYU=
133133
github.com/urfave/cli/v2 v2.27.7/go.mod h1:CyNAG/xg+iAOg0N4MPGZqVmv2rCoP267496AOXUZjA4=
134134
github.com/vektah/gqlparser/v2 v2.5.30 h1:EqLwGAFLIzt1wpx1IPpY67DwUujF1OfzgEyDsLrN6kE=
135135
github.com/vektah/gqlparser/v2 v2.5.30/go.mod h1:D1/VCZtV3LPnQrcPBeR/q5jkSQIPti0uYCP/RI0gIeo=
136-
github.com/wundergraph/astjson v1.0.0 h1:rETLJuQkMWWW03HCF6WBttEBOu8gi5vznj5KEUPVV2Q=
137-
github.com/wundergraph/astjson v1.0.0/go.mod h1:h12D/dxxnedtLzsKyBLK7/Oe4TAoGpRVC9nDpDrZSWw=
138-
github.com/wundergraph/go-arena v1.0.0 h1:RVYWpDkJ1/6851BRHYehBeEcTLKmZygYIZsvBorcOjw=
139-
github.com/wundergraph/go-arena v1.0.0/go.mod h1:ROOysEHWJjLQ8FSfNxZCziagb7Qw2nXY3/vgKRh7eWw=
136+
github.com/wundergraph/astjson v1.1.0 h1:xORDosrZ87zQFJwNGe/HIHXqzpdHOFmqWgykCLVL040=
137+
github.com/wundergraph/astjson v1.1.0/go.mod h1:h12D/dxxnedtLzsKyBLK7/Oe4TAoGpRVC9nDpDrZSWw=
140138
github.com/wundergraph/go-arena v1.1.0 h1:9+wSRkJAkA2vbYHp6s8tEGhPViRGQNGXqPHT0QzhdIc=
141139
github.com/wundergraph/go-arena v1.1.0/go.mod h1:ROOysEHWJjLQ8FSfNxZCziagb7Qw2nXY3/vgKRh7eWw=
142140
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAzt5X7s6266i6cSVkkFPS0TuXWbIg=

v2/pkg/engine/datasource/grpc_datasource/execution_plan.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,23 +281,23 @@ func (r *RPCExecutionPlan) String() string {
281281
result.WriteString("RPCExecutionPlan:\n")
282282

283283
for _, call := range r.Calls {
284-
result.WriteString(fmt.Sprintf(" Call %d:\n", call.ID))
284+
fmt.Fprintf(&result, " Call %d:\n", call.ID)
285285

286286
if len(call.DependentCalls) > 0 {
287287
result.WriteString(" DependentCalls: [")
288288
for k, depID := range call.DependentCalls {
289289
if k > 0 {
290290
result.WriteString(", ")
291291
}
292-
result.WriteString(fmt.Sprintf("%d", depID))
292+
fmt.Fprintf(&result, "%d", depID)
293293
}
294294
result.WriteString("]\n")
295295
} else {
296296
result.WriteString(" DependentCalls: []\n")
297297
}
298298

299-
result.WriteString(fmt.Sprintf(" Service: %s\n", call.ServiceName))
300-
result.WriteString(fmt.Sprintf(" Method: %s\n", call.MethodName))
299+
fmt.Fprintf(&result, " Service: %s\n", call.ServiceName)
300+
fmt.Fprintf(&result, " Method: %s\n", call.MethodName)
301301

302302
result.WriteString(" Request:\n")
303303
formatRPCMessage(&result, call.Request, 8)

v2/pkg/engine/resolve/fetchtree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,6 @@ func (p *PlanPrinter) printRepresentations(reps []Representation) {
383383

384384
func (p *PlanPrinter) print(lines ...string) {
385385
for _, l := range lines {
386-
p.buf.WriteString(fmt.Sprintf("%s%s\n", strings.Repeat(" ", p.depth), l))
386+
fmt.Fprintf(&p.buf, "%s%s\n", strings.Repeat(" ", p.depth), l)
387387
}
388388
}

0 commit comments

Comments
 (0)