Optimizing non-tail recursions for sequences #18213
Labels
Area-Compiler-Optimization
The F# optimizer, release code gen etc.
Area-Compiler-StateMachines
Sequence, list, task and other state machine compilation
Feature Request
help wanted
Milestone
F# now optimizes tail recursion when generating sequences.
The above tail recursion will be successfully optimized and the performance will be linear.
At the same time, the above
head
recursion will not be optimized, and the performance will be quadratic.To optimize tail recursion, the
GenerateNext
method can return the flag (2) to go to the next iterator and thus the tail recursion execution speed will become linear rather than quadratic.I propose adding to this method the ability to call the next iterator and return execution to the current iterator. Flag 3 will call the next iterator and return execution to the current iterator. This will optimize the speed of all simple recursions to linear, and not just simple tail recursions.
To support the ability to call the next iterator and return to the current one, add a stack of iterators in the
GeneratedSequenceBase<int>
class. Adding a stack of iterators will allow you to optimize all types of simple recursions, not just tail ones.The text was updated successfully, but these errors were encountered: