Skip to content

Commit 2d88acf

Browse files
swalkinshawclaude
andcommitted
Rewrite FieldsWillMerge to flatten fragments and deduplicate by signature
Replace the exponential recursive fragment cross-comparison algorithm with a linear field-flattening approach based on: https://tech.new-work.se/graphql-overlapping-fields-can-be-merged-fast-ea6e92e0a01 Instead of comparing fields-vs-fragments and fragments-vs-fragments separately (O(n*m*k) where m=fragments, k=nesting depth), flatten all fragment spreads into a single response-key map and compare within it. Key optimizations in the new algorithm: - Deduplicate fields by signature (name + definition + arguments) to avoid redundant comparisons — fields_merge benchmark: 3.1s to ~1.8ms - selections_may_conflict? fast path skips validation when all direct children are unaliased unique-named fields with no fragments - Cache collect_fields results per (node, return_type) to avoid re-expanding the same sub-selections across comparison contexts - Track compared sub-selection node pairs to prevent infinite recursion - Store single Field directly in response_keys hash, only wrap in array on collision (saves ~1200 array allocations) - Lazy visited_fragments allocation (nil until first fragment spread) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 06d4748 commit 2d88acf

File tree

2 files changed

+250
-237
lines changed

2 files changed

+250
-237
lines changed

0 commit comments

Comments
 (0)