Discussion of adding TCO when closure is detected
See original GitHub issueWhen closure is detected what about pre-processing using a combination of copying params/var decelerations to a state object (when those refs are used via closure) in the function and update all refs to point to this state.
And converting all declared functions in the closure to automatically invoked curried functions that apply the state ref via closure.
I believe this would fix any issues related to function scoping rules including referencing of primitive datatypes since the automatically invoked curried functions would be applied with object refs and would keep that reference even if the parent scope re-assigned a new object ref to the state object variable
Basically a statement like this
function someMethod(min, b) {
const val = b.find(s => s.min < min)
...
return someCondition ? someMethod(val.min, someStatementOf(val)) : val.min
}
would convert to something like this
function someMethod(min, b) {
var _b, _min
...
while(true){
// at start of each iteration assign _state to a new object with updated values
// this allows for automatically invoked curried functions that were applied in a previous iteration to
// keep ref to that object while the next iteration scope can work cleanly on the new object with
// updated values
const _state = {
min,
}
const val = b.find((state => s => s.min < state['min'])(_state))
if(someCondition){
_min = val.min
_b = someStatementOf(val)
b = _b
min = _min
continue;
}
else {
return val.min
}
}
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Uncover All Hidden Lifecycle Ownership Costs. Find TCO in 6 ...
1. Describe the Acquisition or investment and its role in the business, Define TCO Lifespan in years, as either ownership life, economic life,...
Read more >Tail call optimiztion (TCO) in ES6 & Node.js · Issue #3 - GitHub
There is some concern about TCO and how it plays out in VMs and it'd be worth us being aware of this so...
Read more >Understanding Total Cost of Ownership of Serverless and ...
Last week I published an article discussing when serverless is more expensive than containers. In that post, I did a simple comparison ...
Read more >What Does TCO Really Mean? - Zimbra : Blog
But, not understanding the nuances of total cost of ownership (TCO) can add up over time, both in CapEx and OpEx.
Read more >Three-Way Handshake - an overview | ScienceDirect Topics
2 TCP Connection Establishment. As discussed above, a connection is established using a three-way handshake procedure. The flow of data in each direction...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@xtuc yea I completely overlooked that _state was being declared in the while loop and so you are right the automatically invoked curried function is not needed
Thinking more about it, I agree it is probably not a safe assumption.
Could you elaborate a little more? Sorry if I am completely missing something I am pretty new to this subject 😆
I should have a pull-request ready by the end of the week to with a P.O.C.
I was wondering about:
The two
min
declarations should end up overwritting themself in the state.