-
-
Notifications
You must be signed in to change notification settings - Fork 566
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
Improve performance by disabling return/resolved values validation #1493
Comments
My instinct says that the additional check for whichever setting controls this behaviour might eat up some of the benefits afforded by it. Making this as fast as possible would require having a code path that does no checks at all, but also does not checks if that behaviour is enabled. This would require duplicating/rewriting substantial parts of the executor, as well as possibly swapping the default field resolver and other parts that have sanity/safety checks. Feel free to explore this in a pull request, along with benchmarks to test the effectiveness. You can also use a custom executor in your own project, see graphql-php/src/Executor/Executor.php Line 78 in 3ae4185
|
FTR I would be interested in this. Once payloads returned exceed a significant size (in the multi-mega-byte range), I've seen that when profiling (used xdebug & PhpStorm xdebug snapshot analyzer) the micro-overhead for a single field becomes measurable in the big picture to the point it starts to rival the slowest part in those requests, usually the database. |
FTR? |
For The Record |
btw https://github.com/zalando-incubator/graphql-jit have thing called
I will try to make test in few days to see what's the gain. @mfn can you point me where most execution time comes from? |
@spawnia another thing that could improve performance is skipping
in case if document is cached. If document is cached - it was already validated somewhere in the past. |
basically 100-200ms improvement on one specific query on our side.
But i'm not sure how to incorporate this into here. I basically copied StandardServer, Helper and Grapql::promiseToExecute into my bundle in order to achieve that. https://github.com/Warxcell/graphql-bundle/blob/main/src/Controller/GraphQL.php#L231-L257 Any advice how to proceed with this one? |
I've tested with blackfire, and from 300ms total response time, we have 80ms lost in @spawnia what about using |
The performance of an API is a key point. Any small improvement in the response time would be very interesting! (and these benchmarks look promising) |
you can achieve same results by copy-paste-modify StandardServer.php You can see what I've done here: https://github.com/Warxcell/graphql-bundle/blob/main/src/Controller/GraphQL.php ( think https://github.com/Warxcell/graphql-bundle/blob/main/src/Controller/GraphQL.php#L254-L280 is the most important part - it skips parsing && validation of query if its cached) The question is - Can we incorporate that directly into this package? |
I don't want to change the default behaviour of this library in production settings. I very much appreciate how it prevents bad data from ever reaching clients, since we can be fearless and not use defensive programming there. |
The thing is, one may use phpstan/psalm for resolvers - and thus does not need to validate data at runtime. |
🚀 Bounty Alert!💰 A bounty of $15.00 has been created by omarsoufiane on BountyHub. 🔗 Claim this bounty by submitting a pull request that solves the issue! Good luck, and happy coding! 💻 |
@Warxcell did you examined this issue/idea any further? I was debugging slow API responses with xdebug and came to same conclusions - a lot of time it taken by data validation. I do not need this feature that much, especially that it takes a lot of time to execute. So I was looking for some option to just disable it in lighthouse or graphql-php, but was suprised surprised that there is not such thing. I do know that such validation is Graphql advantage, but it should be optional in my opinion. In many cases my data typing is validating by PHP itself by build in php8 typing. If some of my functions will return for example "string" instead of "int" - php will crash, so I do not need graphql-php check it for me again. Also ideally it could be enabled on dev/test environment, and disabled on production. If my query is working and validating fine on local and while testing, i do not see the point of checking it again on production.
So again, it's very valid point, default should be as it is right now, but it could be configurable, like in that JS implementation. @spawnia what do you think? |
I did following patch
➕ what I've mention above. (Query parsed, validated - then if valid - cached, so next time if query is found in cache - its not validated - because only validated queries are cached). (More info here: #1493 (comment)) ➕ there is one more optimization, pending to be merged. #1587 This one caches argument resolution. So it will be very beneficial if you have list which may have some fields with many arguments. Like mention above: for specific query I got 100-200ms improvement with these changes. |
Tried that already, commenting also other asserts, with 0ms difference in my case.
Good idea but it is not necessary in my case. Lighthouse (that is using graphql-php) already does that out of the box. I checked source and tested it - query AST is indeed cached as array, exactly like in your example. So parsing should be fast. In your case @Warxcell if I understand correctly, only this query caching did the real difference, but it's outside of this issue scope, because you changed query part of request, on return part, like described in first post. I'm not sure what is going on in PR you provided (but I will for sure test it after release), but I wonder if is there anything that could be done to speed up data return. I'm out of ideas for now. |
I wanted to but today I cannot reproduce situation where About So even that it was called a lot of times, according to profile it took close to nothing. I tried to make different queries, but results were similar. It's interesting that it took 40ms in your case. I cannot see it in graph - do you know to many times it was called? But looking in vendor for more
so there might be something to it. Maybe I would get different results with blackfire that you used. But being forced to pay "monthly" subscription up front for whole year is just ripping off that I will not support such bad business practice with my money. |
What do you think about this one? The use-case is to gain a little bit of performance, by disabling resolver's returned value validation - and just trusting it.
No idea how much will gain - just throwing it in the wild and see what people think. :)
The text was updated successfully, but these errors were encountered: