Repository navigation
FastSchemaValidator - #4549
FastSchemaValidator#4549xuorig wants to merge 2 commits into
Conversation
6b2361e to
4762b7c
Compare
Test ReportTest Results
Code Coverage (Java 25)
Changed Class Coverage (11 classes)
|
|
hey @xuorig ... thanks a lot. We will continue to prioritize performance and also thanks to AI we are not so concerned anymore with more specialized code if it serves our goals. Hence I am leaning toward using the FastSchemaValidator everywhere and get rid of the other one. cc @bbakerman your thoughts? |
4762b7c to
0e8eb4d
Compare
Makes sense to me! I've updated the PR to replace the validator entirely. There was also another approach where we could have used Edit: Actually I forgot |
63782b7 to
ed77804
Compare
If this is faster we want it - large schemas are a bottle neck in graphql-java - we are hitting that in Atlassian where schema loading is taking longer than we wish (with 35K types and 85K fields) =- getting 18x to 25x is a rare find Given that this passes all tests and the tests havent been fundamentally changed - I think this should be the new way we validate. |
bbakerman
left a comment
There was a problem hiding this comment.
I feel we should go with this approach
Thanks
|
Local bench. A bit of overhead due to calling methods on every elements no matter what, but still a huge improvement. |
b6aae19 to
465e0fd
Compare
|
Rebased due to the new |
465e0fd to
899d448
Compare
…erser walk SchemaValidator now applies its rules by iterating the schema's types and directive definitions directly, instead of running ten GraphQLTypeVisitor rules over every schema element with SchemaTraverser. validateSchema keeps the same signature; getRules() and the rule visitor classes are removed. Behaviour differences: - errors are reported grouped by type, so their order changes - elements shared between several parents are checked under each of them, where the traversal only checked them under the first parent it reached - schemas whose programmatic default values form a cycle now fail with an InvalidSchemaException instead of a StackOverflowError On large-schema-4 validation drops from ~407ms to ~16ms and allocation from ~532MB to ~12MB per run (SchemaValidatorBenchmark).
SchemaValidator keeps the single loop over types and directive definitions and calls the hooks of a SchemaValidationRule per rule class. Each validateSchema call creates its own rule instances, so per-validation state stays in final fields. InputValueValidator holds the value coercion shared by DefaultValuesAreValid and AppliedDirectiveArgumentsAreValid.
899d448 to
56c99ea
Compare
|
Rebased again! |
|
@xuorig my AI said: [P2] Arguments inside legacy directive applications lose validation. The new loop checks their supplied values, but skips other argument rules. An Int argument with default "bad", or an undefined directive attached to that argument, now passes schema construction. Both are rejected on master. [P2] Schema-level legacy directives are omitted. The validator iterates types and directive definitions, but never schema.getSchemaDirectives(). An invalid argument default on a schema-level directive now passes construction. We have some other PRs which overlap slightly with that .. .I might push changes to this branch |
|
@andimarek please feel free yes, thanks. |
Introduces a
FastSchemaValidator, which doesn't useSchemaTraverser. Running locally, I achieve ~20x speedup compared toSchemaValidator. I've chosen to introduce it as the default validator for theFastBuilder.For correctness, with the help of Opus I've ran every single GraphQLSchema build in the test suite with both validators and they came back with the same set of errors. I added a new set of comparison tests too (similar to FastBuilder) for correctness and making sure they stay aligned.
A benchmark was also added.
Let me know how you want to handle this, we could:
Local Results: