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
check_key_fields validation optimization for projects with heavily reused fragments #3656
Comments
Thanks for sending this! We are monitoring the compile time but don't have any tests to detect such regressions at the moment. That's definitely something to add.
In CheckKeyFieldsScope.checkField,
That's impressive 👏 ! Want to open a pull request and we can go from there? |
Hi 👋 Trying to look at this, for now I couldn't reproduce a case where |
@martinbonnin Awesome thanks for the patch, the build speed is much better now. For reference, I tested compilation of Apollo 3.0 GA in a multi-module project using Also, I’ve posted a PR for optimizing fragment spreads. Please take a look and provide any feedback. |
All the thanks goes to @BoD who did all the work there :-) Thanks for the PR, we'll take a look quickly ! |
@martinbonnin @BoD I noticed that Apollo React provides the ability to disable normalization for specific types. Does apollo-kotlin support this? (And if so, can this be used to exclude types from validation?) |
@apramana we don't have anything like this at the moment. Feel free to open a separate issue to track this. |
I'm closing this one in favor of #3966. As of In the future, we'll want to optimize that part of the codegen but before we optimise, we'll need a measure of what we're optimizing, which is what the above issue is about. |
Summary
Codegen takes substantially longer in v3 compared to v2 in projects with heavily reused fragments due to
check_key_fields
validation.Version
3.0.0-beta05
Description
Hello - I am in the process of migrating our project (which makes extensive use of nested and reused fragments) to Apollo 3, and noticed that the codegen task takes significantly longer for us than it does in v2. For comparison, codegen (excluding compilation) on our root module takes ~30s in v2 and ~3 min in v3.
To investigate, I cloned the Apollo compiler and found that most of the time was spent on the checkKeyFields call on fragments. Within check_key_fields.kt, I added a println and noticed that identical paths are being checked more than once. Am I correct in understanding that
checkField
should only be called once per unique path value (and that selections remain stable)? If so, could a set of checked paths be maintained so that duplicate calls are avoided? This change substantially reduces the time this class takes to run (our root module codegen comes down to 40s with this optimization) but I'm unsure if it breaks the completeness.The text was updated successfully, but these errors were encountered: