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

Performance Degradation with flutter_rust_bridge_codegen in Complex Projects #2509

Open
kotepillar opened this issue Jan 21, 2025 · 4 comments
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc

Comments

@kotepillar
Copy link

Description:
I’m experiencing very slow performance when using flutter_rust_bridge_codegen in a more complex Flutter/Rust project. Specifically, when I run:

flutter_rust_bridge_codegen generate --watch

the process takes a very long time to complete. Below is an example log:

Watching file changes on /home/my_app/rust/src...
[73.3s] Parse
  └── [73.3s] Cargo expand & syn parse
  └── [0.0s] Parse HIR
  └── [0.0s] Parse MIR
[0.0s] Generate
[2.0s] Polish
  └── [1.2s] Run Dart fix
  └── [0.8s] Run Dart formatter
  └── [0.1s] Run Rust formatter
  └── [0.0s] Auto upgrade

Notably, the parsing step alone takes more than 70 seconds, which severely impacts productivity.

Additionally, this performance issue appears to affect my IDE’s Rust analysis too (e.g., rust-analyzer in VS Code). Even detecting a simple function name typo can take a very long time to register.

Is this behavior a known limitation or a common issue when the project is large/complex?
Are there any suggested optimizations or configurations to improve code generation and analysis speed?
I’m happy to provide more details about my project setup and configuration if needed.

Copy link

welcome bot commented Jan 21, 2025

Hi! Thanks for opening your first issue here! 😄

@fzyzcjy
Copy link
Owner

fzyzcjy commented Jan 21, 2025

Hmm, "Cargo expand & syn parse" phase executes cargo expand and syn's parse. Thus it may not be possible for frb to optimize it :(

Are there any suggested optimizations or configurations to improve code generation and analysis speed?

Brainstorms:

  • Split the project: make the frb-related code in a small crate, and other code in another (big) crate.
  • Do not use --watch, but only generate when there are changes that you know will affect the API

Additionally, this performance issue appears to affect my IDE’s Rust analysis too (e.g., rust-analyzer in VS Code). Even detecting a simple function name typo can take a very long time to register.

Not sure, just random guess: is it possible to be caused by cargo expand somehow hold some global lock on codebase? Or maybe the cargo expand takes cpu? Maybe need some experiment to dig more if needed.

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Jan 21, 2025
@kotepillar
Copy link
Author

kotepillar commented Jan 22, 2025

@fzyzcjy Thank you for the quick response. My project schedule is quite tight at the moment, so I’ll need to hold off on deeper testing and feedback for now. Once I have time to explore your suggestions and see how they might help, I’ll let you know. Thanks again!

@fzyzcjy
Copy link
Owner

fzyzcjy commented Jan 22, 2025

You are welcome! Feel free to ping me if there are any further questions/experiments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc
Projects
None yet
Development

No branches or pull requests

2 participants