Skip to content

perf: clone only args in executeOperation, not the whole params#5

Open
Loskir wants to merge 1 commit into
CandoImage:mainfrom
Loskir:perf/execute-operation-clone-args-only
Open

perf: clone only args in executeOperation, not the whole params#5
Loskir wants to merge 1 commit into
CandoImage:mainfrom
Loskir:perf/execute-operation-clone-args-only

Conversation

@Loskir

@Loskir Loskir commented Jun 17, 2026

Copy link
Copy Markdown

Summary

executeOperation deep-clones the entire params for every nested operation. The library never mutates scope / model / operation — only args is rewritten as operations are transformed — so sharing them by reference should preserve the existing isolation guarantee.

Benchmark

I ran withNestedOperations on a nested query before and after the patch, here is the result

replies nested N levels before (clone whole params) after (clone args only) speedup
2 354 µs 82 µs 4.3×
4 711 µs 146 µs 4.9×
8 1.80 ms 0.32 ms 5.7×
16 5.92 ms 0.89 ms 6.6×

This change cuts pre-processing time by ~75-85% depending on nesting. Overall complexity is still worse than O(n) but most of the redundant work is removed.

Here are some flamegraphs (depth 24):

Before (11ms):

image

After (1.17ms):

image

executeOperation deep-cloned the entire params for every nested operation.
Since params carries scope.parentParams (the ancestor chain up to the root
query), that redundantly re-cloned every ancestor's args on every nested op —
work that grows sharply with nesting depth. Only args is mutated downstream;
scope/model/operation are read-only, so cloning just args keeps the
no-mutation guarantee and drops the redundant copy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant