-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
large enums slow down compilation #9081
Comments
This commit improves the compile time of generating bindings for enums with many cases in them (e.g. 1000+). This is done by optimizing for enums specifically rather than handling them generically like other variants which can reduce the amount of code going into rustc to O(1) instead of O(N) with the number of cases. This in turn can greatly reduce compile time. The tradeoff made in this commit is that enums are now required to have `#[repr(...)]` annotations along with no Rust-level discriminants specified. This enables the use of a `transmute` to lift a discriminant into Rust with a simple bounds check. Previously this was one large `match` statement. Closes bytecodealliance#9081
I've tested that with #9122 the enum in question goes from generating 80_000 lines of code to 8_000 lines of code, which should be a large improvement. When that lands though can you confirm that it improves things locally as well? If the compile time is still too long I'll look into this further and see what else is generating a lot of code. |
@alexcrichton I would be happy to test it! |
* Improve codegen for enums with many cases This commit improves the compile time of generating bindings for enums with many cases in them (e.g. 1000+). This is done by optimizing for enums specifically rather than handling them generically like other variants which can reduce the amount of code going into rustc to O(1) instead of O(N) with the number of cases. This in turn can greatly reduce compile time. The tradeoff made in this commit is that enums are now required to have `#[repr(...)]` annotations along with no Rust-level discriminants specified. This enables the use of a `transmute` to lift a discriminant into Rust with a simple bounds check. Previously this was one large `match` statement. Closes #9081 * Fix some tests * Add repr tag in fuzzing * Fix syntax for Rust 1.78
@alexcrichton tested the changes and they definitely solved my issue! thanks a lot! |
Great, thanks for testing! |
Related to bytecodealliance/wit-bindgen#1019
I have a large enum with 1424 cases. While it's completely broken on the client side, it works as expected on the host side, but compilation takes ages. On this Macbook Pro M3 Pro it takes 1 minute longer on a fresh compile than without the enum.
I attached the wit for testing.
icons.wit.txt
The text was updated successfully, but these errors were encountered: