-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix: only run generate code once #3436
Conversation
Converted to draft while I investigate the CI errors |
Hi @StevenACoffman I may need some pointers on this, the diff is all in the federated example. It's added |
I believe the issue was due to the order of running things. The plugins modify the data that gets passed to the main generateCode function. So by reordering things, the codegen now matches the examples |
Hey, sorry I've been slow to respond to this. I really appreciate you taking this on! This looks perfectly sound to me, but I would like to get some more people to try this out in case there's a reason I'm not seeing why something would need to run both before and after (more like a middleware). After all Hyrum's Law may apply:
|
No problem at all @StevenACoffman. Thanks 🙏 |
This won't cause an issue for dataloadgen. dataloadgen exists only at run time, not generation time. It's not a plugin I got some data points for our biggest graph, though, to show that it helps us a lot too:
|
Ok, I'm going to merge this 🤞 , but I'm also going to hold off on a new release for a bit in case there's some late feedback and we need to alter things. BTW, this might help with #3414 Unfortunately, very few people pay attention to changes until after a release and they try to put things into their own prod environments. |
@StevenACoffman Look good on https://github.com/theopenlane/gqlgen-plugins against our main schema. Appreciate you checking! |
@StevenACoffman |
@vikstrous is that schema available publicly? I'm looking into if there are any other obvious improvements and would like more schemas to test against. So far I've found that this prune function takes a significant amount of time on our schema. |
No, sorry, it's a private codebase. I've noticed that autobind is one source of slowness because of the size of the repo. There are a lot of dependencies, so loading the packages can take time |
You might look at #3372 @Brookke Sidenote: I'm not sure if it's helpful, but I shared with you a private repo with just Khan Academy's gqlgen configs, service schemas, and federation composed supergraph. We're a non-profit, so we don't have trade secrets, and we only accept the queries from our safelist, so I'm not super concerned with sharing. However, it would be better if it wasn't passed around too much, since that kind of thing invites attackers. The really huge gqlgen schemas I'm aware of like ones the reddit folks and uber folks use are not public. Honestly, one of the things that gqlgen is really missing is a set of realistic benchmarks and profiling to get a sense of where are the performance bottlenecks (during codegen but also in runtime), so this would be hugely valuable work. Performance optimizations can make the code harder to maintain, so we only want to do it where it makes a big difference, and right now we don't know where that would be. |
Thanks for sharing @StevenACoffman. My initial findings centre around the Prune function, basically it calls This suggestion might help #2308 Alternatively, I was wondering if a refactor could move the call to |
A PR for either/both would be very welcome! If there's a breaking change necessary in the name of progress, we should put a config option and let people opt-in (or at least opt-out). For instance, if the generated files were not formatted, people would be annoyed as their linters would complain (even though they can exclude generated files, or add a pre-lint format step after generation), even though it would be much faster. |
If you see any other userful performance improvement suggestions in issues and want to call them out to me here, I can tag them as performance for others. I prioritize paying attention to PRs with my volunteer free time, but I often have stretches of time where I have to ignore issues (like camping) and then can never get enough time to circle back to look at them. |
in issue #2526 it's noted that
codegen.GenerateCode
is ran twice theres a vague PR that reverted this duplication #1100, but I am not clear why.In my testing using a particularly heavy schema file I found the following
I have:
closes: #2526