-
Notifications
You must be signed in to change notification settings - Fork 122
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
Exponential complexity of unions generation #558
Comments
Hi! Thanks for the repro, this makes it easier for me to figure out what is happening. |
Can you maybe also produce a repro that runs into this pathological case with reuse_fragments: false? without reuse_fragments: false, the example builds fine and quickly for me. So you definitely found a performance bug with reuse_fragments, but I would like to focus on the general bug that prevents you from building without it first. |
I found an issue in gql_code_builder, and found a potential fix but it's not testes/verified yet. you can test it by using dependency_overrides:
gql_code_builder:
git:
ref: possible_reuse_fragment_fix
url: https://github.com/gql-dart/gql.git
path: codegen/gql_code_builder
|
Awesome! It looks like you fixed the problem related to a long time of processing. Now file that couldn't process within 9+ hours has been finished in 1s. 🎉 So I was able to build some part of the queries we use in the project, but when I tried to build the all queries then after 30 minutes of building I got an
So it's probably another issue, and for now, I do not have any more specific information about it. |
@knaeckeKami is that question still relevant?
|
Yes! I would love the see a runnable reproduction of the issue where I heard reports of that from different users, but I could not reproduce it myself yet. |
Actually, looking at the error message, it seems to fail to generate the serializers in the built_value step. That's surprising to me, generating the list of serializers is not particularly complex. If you cannot provide a reproducible example, it would also help if you cold fork built_value_generator and print more details (e.g. the stack trace when this exception happens·. |
So the example from the repo I provided works fine with the disabled But in our project, we get
I will try to provide more details soon. |
Here you have a full stack trace of out-of-memory error with
I will try to create some reproducible example in the next few days. |
Thanks. Maybe the aggressive memoization of built_value_generator + keeping all the I removed a few suspicious @memoized fields in built_value_generator in my fork https://github.com/knaeckeKami/built_value.dart/tree/relax_memoization . you can try it out using dependency overrides for built_value_generator built_value_generator:
git:
url: https://github.com/knaeckeKami/built_value.dart.git
ref: relax_memoization
path: built_value_generator This will probably increase the code generation time significantly, but might be a workaround until a fix in built_value is found. |
Yep, that worked, thanks 🎉 , but the code has been generating about 2 hours. Let's leave it for now. I will back to the topic in a few days with a reproducible example (I hope so). |
Glad to hear that! There are definitely ways to fix this without disabling memoization completely and re-calculating the fields on every access, built_value_generator just needs to be a bit smarter with keeping references to objects with all these calculated fields. This should improve the built time again. I opened an issue in built_value. |
Hi @knaeckeKami! I don't know why but, bcs of that code reusing fragments doesn't work. So almost every query has to generate new fragments. BUT there is still some issue. Now we have an issue with the deserialization of fragments used in unions Do you have any idea how to fix that? 🤔 If you need a repo with an example to reproduce then let me know 🙏 BTW we use that branch with fix. dependency_overrides:
gql_code_builder:
git:
ref: possible_reuse_fragment_fix
url: https://github.com/gql-dart/gql.git
path: codegen/gql_code_builder |
cool! Is this a new problem? The reuse_fragment flag is still experimental, and the author actually opened a PR with some fixes which i did not get to merge yet / i also asked them to verify that the bug with the exponential codegen time on unions is fixed. It's possible that this PR: https://github.com/gql-dart/gql/pull/417/files fixes the deserialization issue, but it's possible that the exponential codegen time is still there (that was just a one line change though and should be easy to integrate) If you disable the reuse_fragment flag, I guess the codegen time and size is still too high? |
yep
I am going to check it ❤️ |
Checked. It looks like it solves the aforementioned problem, but I am getting some errors related to incorrect return type. I am going to investigate it and create some example. |
Hi! Awesome package! Good job! 😊
We are switching quite complex project from artemis to ferry and we were not able to generate code using ferry. It was throwing out of memory error and then we found reuse_fragments option that helped (probably), but then the generation can't finish. It takes infinite time (after 9 hours of processing a single file I gave up).
We've made an investigation and it turned out that the complexity of unions in our queries is the problem.
We have a timeline query that can return 1 of 8 possible objects. We are not able to process that file, but if we remove some of the fragments from the query then we can do it and it doesn't matter which one we remove:
I've prepared a repository with an example to reproduce the issue. The example is much simpler than our real project so it can generate even 10 fragments, but it takes about 2 minutes.
The time is checked in the following way:

It looks like calling https://github.com/gql-dart/gql/blob/1cabae81a96db119b00d1502043974d1f7b49f70/codegen/gql_code_builder/lib/data.dart#L128 function is responsible for such long times.
Is there any plan to improve that? In our case ferry seems to be not usable 😞
The text was updated successfully, but these errors were encountered: