Skip to content

Compiler inlines and optimizes the whole function to return 330 #2

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

Closed
jhorstmann opened this issue May 21, 2024 · 1 comment
Closed

Comments

@jhorstmann
Copy link

Rust and its pattern matching is fast, but not that fast ;)

Rustc 1.77 seems to be able to optimize the whole pattern_matching function to the equivalent of return 330.

Rustc 1.78 seems to be able to do the same optimization also for the dynamic_dispatch version.

See https://rust.godbolt.org/z/zTrzhTbze for the assembly output.

A possible improvement to the benchmark could be to change Action to take a parameter, and to tunnel the parameter value through criterion::black_box to avoid compiler optimizations based on that value.

@tusharmath
Copy link
Contributor

Thank @jhorstmann I have fixed the benchmark. Appreciate your help 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants