You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stop re-walking variable values in validateOneOfInputTypes - #4564
query ($f: Filter) { a0: f(filter: $f) a1: f(filter: $f) ... }
aliases before after
1 16 ms 13 ms
1000 1615 ms 17 ms
{ items { f(filter: $f) } } over 10,000 items: 21.6 s before, 0.33 s after
getArgumentValues calls validateOneOfInputTypes for every argument of every field invocation, and for a variable reference it walks the whole coerced variable value: every input object field and, since #4494 (mine), every list element. variable values are already coerced and checked once per request in coerceVariableValues, so each field that references the variable repeats the full walk. the cost is variable size times field invocations, which makes it a request amplification any client that can send variables can trigger, and the schema does not need a @oneOf type, only a list or input object argument. coercion itself also ran the recursive walk at every nested input object, so a value nested 120 deep was walked once per ancestor (50,000 leaves: 122 ms before, 11 ms after).
validateOneOfInputTypes now returns for variable references, coerceVariableValues checks variable default values the way it already checked supplied ones, and external values are checked once after coercion instead of at every level. one visible change: an invalid default like query ($v: [OneOf] = [{a: null}]) is now rejected during variable coercion, the same as a supplied [{"a": null}], instead of as a field error. the getArgumentValues rows that fed hand-built invalid CoercedVariables (a state coercion no longer lets through) moved to a coerceVariableValues test with the same values and exceptions. the new default value test and the @Timeout(10) end to end test fail before the change.
partly. both fix the per-level re-walk during variable coercion in externalValueToInternalValueImpl, and #4542's per-level check covers that part fine. the larger cost here is a different call site: getArgumentValuesImpl runs validateOneOfInputTypes on every field invocation, and for a $var argument it walks the whole coerced variable again. #4542 leaves that path as is, so a variable referenced by many fields is still walked once per field. same machine, JDK 25, query ($filter: Filter) { items { f(filter: $filter) } } over 10,000 items with a 100,000 element filter: 27.3 s on #4542's head, 0.24 s on this branch.
if #4542 lands first i can drop the coercion hunk here and rebase, leaving just the VariableReference early return and the variable default check in externalValueToInternalValueForVariables. those don't overlap with #4542.
This branch has not been deployed
No deployments
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
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.
input Filter { and: [Filter!] or: [Filter!] not: Filter eq: String },Query.f(filter: Filter): Int,$f={and: [{eq: "x"} x 100,000]}(~1.1 MB of variables), JDK 25:getArgumentValuescallsvalidateOneOfInputTypesfor every argument of every field invocation, and for a variable reference it walks the whole coerced variable value: every input object field and, since #4494 (mine), every list element. variable values are already coerced and checked once per request incoerceVariableValues, so each field that references the variable repeats the full walk. the cost is variable size times field invocations, which makes it a request amplification any client that can send variables can trigger, and the schema does not need a@oneOftype, only a list or input object argument. coercion itself also ran the recursive walk at every nested input object, so a value nested 120 deep was walked once per ancestor (50,000 leaves: 122 ms before, 11 ms after).validateOneOfInputTypesnow returns for variable references,coerceVariableValueschecks variable default values the way it already checked supplied ones, and external values are checked once after coercion instead of at every level. one visible change: an invalid default likequery ($v: [OneOf] = [{a: null}])is now rejected during variable coercion, the same as a supplied[{"a": null}], instead of as a field error. thegetArgumentValuesrows that fed hand-built invalidCoercedVariables(a state coercion no longer lets through) moved to acoerceVariableValuestest with the same values and exceptions. the new default value test and the@Timeout(10)end to end test fail before the change.