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

Internal std::variant access optimizations #161

Open
igrekster opened this issue Jan 25, 2024 · 3 comments
Open

Internal std::variant access optimizations #161

igrekster opened this issue Jan 25, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@igrekster
Copy link

Been playing around with flux and noticed that the generated code had checks for safe std::variant access, even though the logic ensures that it was safe. I've identified a few places in the code, but there are more patterns like this: igrekster@70ef410

Here is before/after on the Compiler Explorer: https://godbolt.org/z/azfqMbT5j

And a Rust equivalent to compare: https://rust.compiler-explorer.com/z/K6E5xYc3W

@tcbrindle tcbrindle added the enhancement New feature or request label Jan 25, 2024
@tcbrindle
Copy link
Owner

Wow, that's a huge improvement! And it's always nice to know when we generate better code than Rust iterators :)

It's a similar story with GCC: with your changes the example optimises down to an astonishingly small amount of assembly https://godbolt.org/z/c1dexE4Y9.

I'd be very happy to take a PR that implements this optimisation (here and in other places if you find more). I'd prefer not to require C++23 yet on GCC and Clang, but adding our own version of std::unreachable shouldn't be too difficult.

Thanks @igrekster!

@igrekster
Copy link
Author

Unfortunately, I don't have much capacity ATM, but I might look into it some time in the next few weeks. Just wanted to bring attention to this optimization.

@tcbrindle
Copy link
Owner

No problem, I can take a stab at it at some point

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

No branches or pull requests

2 participants