-
Notifications
You must be signed in to change notification settings - Fork 840
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 for schemas with many fields #140
Conversation
@@ -1285,9 +1286,26 @@ func (gl *NonNull) Error() error { | |||
|
|||
var NameRegExp, _ = regexp.Compile("^[_a-zA-Z][_a-zA-Z0-9]*$") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this variable superfluous now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and no. It's not used in the lib anymore, but it's exposed and part of the public API therefore I left it in because I didn't want to break backwards compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, though I'm not sure exporting this variable was deliberate. Maybe it could be marked as deprecated or simply removed anyway (current version is sub 1.0 after all).
Dear maintainers, We profiled graphql-go in our environment, and saw some performance issues associated to a growing schema. What needs to happen to bring this to the finish line? Would it be easier for you to merge if the commits were merged to more small pull requests? Or is there something else we could do? |
This can be closed now? See #267 |
closing this one since #267 addressed the major issue i saw (invariant/printf overhead) |
I did some performance testing and noticed that there is some noticeable overhead once the schema grows.
Commit ccd7f68 introduces a
invariantf
function that formats the error message with fmt.Sprintf. This was done because in CPU profiles Printf regularily came up almost top.I traced the source of the Printf's to defineFieldMap and started replacing there, but later extended to all occurances that I found. The change almost halved query processing time for a schema with 20 fields and also brought down allocations from ~2800 to ~1800.
In fdb793c I tried to eliminate the next biggest source of CPU usage, which was the regex in
assertValidName
. Suprisingly this only resulted in a ~26% decrease in query execution time.58481fc only tries to avoid some slice reallocations in some places where the final slice length is known. This didn't really increase performance much (~1%) but seeing that the garbage collector is already the biggest source of CPU usage I left it in anyways.
I did some benchmarks comparing the changes to master with varying schema sizes.
schema with 1 field:
schema with 20 fields:
schema with 100 fields:
The source for the benchmarks can be found at: https://gist.github.com/sfriedel/81793288bcc373988f6a000062d051ea
I did some testing with the changes and both the tests and my application run flawlessly with them, but still it would be good if someone else takes a look.