-
Notifications
You must be signed in to change notification settings - Fork 563
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
TCO: output closure-free while loop #3183
Comments
@natefaubion It seems that the change to which you've linked is perhaps being overprotective, then? |
(particularly, the "values which might capture variables" criterion) |
Do you have a benchmark that shows the difference? |
https://github.com/matthewleon/purescript-tco-bench This implements a simple sum function on lists. The FFI version is basically the TCO'd version with the closure inlined. benchmarking for TCO: benchmarking for hand-inlined TCO: Granted, this is something of a worst case; summation is so simple that the the overhead of calling into the TCO function shows its weight here. I tried a similar benchmark on list reversal (I can link if you are curious) and the penalty only turned out to be a few %. |
There is some discussion here regarding ES6 compiler output permitting us to use This would be a potentially easy solution to the issue, allowing us to (maybe) revert to the behavior before the merge linked above. Some |
TCO outputs a while loop that calls a function on every iteration, incurring a performance penalty.
An example. Here is the definition of
tailRec
frompurescript-tailrec
:It compiles to the following:
In this case, and many others, the
$tco_loop
function could be inlined into the while loop, simplifying the resulting code and improving its performance.To be sure, I imagine the TCO behavior was initially created this way with good reason, so there might be some situation where we can't safely get rid of the closure. We should seek to document this.
The text was updated successfully, but these errors were encountered: