Skip to content
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 freezed generation speed #834

Open
pixelshot91 opened this issue Jan 6, 2023 · 4 comments
Open

Improve freezed generation speed #834

pixelshot91 opened this issue Jan 6, 2023 · 4 comments
Assignees
Labels
needs triage question Further information is requested

Comments

@pixelshot91
Copy link

I find that freezed code generation is quite slow.
When I launch the code generation with dart run build_runner build --config freezed --delete-conflicting-outputs, it take 22 seconds to generate 15 files.

Describe the solution you'd like
I would like to compile the freezed package because compiled code is usually much faster than interpreted one.
I tried to compile it, but the dependency on dart:mirrors make it fail.

Describe alternatives you've considered
I also try to reduce the number of file freezed should analyze by exclude files I know don't contain freezed annotation.
It decrease the time from around 1 minute to 22 seconds.
I used dart run build_runner serve --config freezed --delete-conflicting-outputs --track-performance to view the time graph and see which builder/file take time to build.
Now, only the file I am interested in are rebuilt, but it is still quite slow

Additional context
I created a code generator with code_builder, which generate about the same amount of code, but it only take 5 secondes with dart run, and under a second with the compile version.
I don't understand why Freezed is so slow. Is it because it analyze all my code base and all its dependencies ?

I use Freezed for many projects, and it always take between 10 seconds and a whole minute to complete.
Using dart run build_runner serve is much faster for incremental rebuild, but it is not always feasible to use it.
It adds a lot of lost time when prototyping an application.
Maybe the issue is in build_runner ?

@pixelshot91 pixelshot91 added enhancement New feature or request needs triage labels Jan 6, 2023
@rrousselGit
Copy link
Owner

I used dart run build_runner serve --config freezed --delete-conflicting-outputs --track-performance to view the time graph and see which builder/file take time to build.

What did it say in your case?

The bottleneck should be the analyzer. Freezed is just doing a bunch of string concatenation. Nothing that should take ages

@rrousselGit rrousselGit added question Further information is requested and removed enhancement New feature or request labels Jan 6, 2023
@pixelshot91
Copy link
Author

image
Here is the report of build_runner: perf_freezed.txt
GitHub does not allow to upload html file, so I changed the extension to txt.

@rrousselGit
Copy link
Owner

It'd help a lot if you could share a reproducible sample.

Since a bit unclear what's the bottleneck with what you shared (since I can't zoom on the time chart). My guess is that it's analyzer that's slow and that as such there's nothing I can do.

@rrousselGit rrousselGit self-assigned this May 10, 2023
@rekire
Copy link

rekire commented Jul 20, 2023

It would be great to have here some improvements. The code generation became while adding new classes over the time by factor 3! In average does the generation take now 45 seconds on my intel mac.

Here is the output of my last run (my mac throtteld as hell but anyway):

[INFO] Running build completed, took 4m 22s
[INFO] Caching finalized dependency graph completed, took 457ms
[INFO] Succeeded after 4m 22s with 24 outputs (183 actions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants