-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OverlappingFieldsCanBeMerged is slow #1786
Comments
of course we can - its an open source project and you can you submit a PR to get this started. |
It doesn't follow the spec, so I'm asking if it's the way to go. I may do it once I will get some free time. |
Are you saying that way the sangria team solved the performance problem was to not follow spec? if so can you expand on that and help us understand what they did and how it deviates? I read that issue but there is a lot of reverse engineering involved and it would be great to get a head start on that |
I didn't read it very much into details, but they looked at the algorithm defined by the spec regarding overlapping-fields-can-be-merged, and introduced some optimizations to it (some caching, and some function call refactorings so they don't check things more than needed). Currently, it is in "experimental" and providing a way how to replace the original validator with the optimized one using their API for validators. Which is not possible in graphql-java if I saw correctly. So the spec algorithm is still the default one, but there is a way to replace it. See also |
Bump. We would like to sort this our for our application, as it's imposing quite a big performance hit for our API. |
@redhead can you provide us with some profiling results? |
I kind of wanted to start a discussion about it first, so I can't give you profiling results of the rewritten algorithm (I can of the current state). Also, as it's not following the spec's pseudocode, I wasn't sure you would be ok of merging it at all. |
How big was the query you are running? Can maybe share it? Thanks |
The query is big (2k lines), it's because we are doing a global search query which can potentially return any type of our app model entity. Because of that, it consists of a lot of inline fragments for "casting" to the right GQL type of the app model entity. Most of the entities don't have a common denominator interface to make it consise. The gist of it is here, it was edited for clarity and to hide our business domain:
|
Please have a look into the sangria bug report (though written in scala, it probably follows the same algorithm): and the query they reported was: |
(I had to delete my previous post from today as it wasn't fully valid.) I took a chance to try to rewrite the algorithm from Scala (sangria) implementation to graphql-java. As you can see, it went quite well: I have a dirty WIP code of the new algorithm rewritten from scala., All the tests from OverlappingFieldsCanBeMergedTest are passing except for these cases:
|
+1 for giving this some serious consideration. I'm looking at a Java profile where, of the 3.8s of CPU time spent in the GraphQL endpoint, 3.2s is spent in OverlappingFieldsCanBeMerged.leaveSelectionSet. |
hi, we are planning to address this issue via #2495 Special thanks to @redhead: we really appreciate the effort you put in, but ultimately we could not accept a scala version of the algorithm from a longterm maintainability POV. But we implemented the same algorithm based on the xing article. We are planning to replace the current validation completely with the more performant one. Andi |
Thanks a lot. It looks great. |
merged now and will be part of 17.0 |
OverlappingFieldsCanBeMerged
can be very slow when many fragments in the query.Scala implementation resolved it by optimizing the algorithm.
See sangria-graphql-org/sangria#12.
Can we do something similar in graphql-java?
The text was updated successfully, but these errors were encountered: