Inline generators before state machine conversion in order to reduce branching #83101
Labels
A-coroutines
Area: Coroutines
A-mir-opt
Area: MIR optimizations
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
C-optimization
Category: An issue highlighting optimization opportunities or PRs implementing such
I-slow
Issue: Problems and improvements with respect to performance of generated code.
As of 6c51ec9, which is the fix for #76181, generators no longer inline in MIR. This results in missing the following optimization opportunity:
should become:
I checked a simple example and LLVM didn't seem to do the inlining, which doesn't surprise me as after the state machine transformation it's going to be quite hard to perform it.
This could be an important optimization because recreating the nested call stack when a generator is resumed can be O(n) in bad cases like this one. (This was brought up as a potential problem when comparing C++ coroutines with Rust generators.)
The text was updated successfully, but these errors were encountered: