Skip to content

Optimize repeated FieldsWillMerge comparisons - #5704

Open
ydah wants to merge 1 commit into
rmosolgo:masterfrom
ydah:optimize-fields-will-merge-comparisons
Open

Optimize repeated FieldsWillMerge comparisons#5704
ydah wants to merge 1 commit into
rmosolgo:masterfrom
ydah:optimize-fields-will-merge-comparisons

Conversation

@ydah

@ydah ydah commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Improve the performance of FieldsWillMerge validation for queries containing many repeated composite fields and shared fragment selections.

Previously, the validator could repeatedly compare the same expanded fragment fields for every pair of parent fields. This caused nested Cartesian comparisons and severe superlinear runtime growth before query execution or authentication.

This change:

  • groups fields with identical sub-selections and compares only one representative from each group
  • memoizes comparisons between equivalent expanded field groups
  • keeps mutually exclusive and non-exclusive comparisons separate
  • adds a regression test that verifies a divergent conflict is still detected without reaching the default validation timeout

Benchmark

Measured using a query with repeated composite fields and a shared fragment containing repeated fields.

Fields Query size Before After Speedup
100 2,320 bytes 193.6 ms 3.14 ms 61.7x
200 4,552 bytes 1,438.4 ms 3.72 ms 386.7x
400 9,000 bytes 11,732.5 ms 8.68 ms 1,351.7x
800 17,864 bytes did not finish within 30 seconds 20.08 ms

The 400-field case is reduced by approximately 99.93%.

@rmosolgo
rmosolgo requested a review from swalkinshaw August 17, 2026 19:00
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