In the context of the async/await PR and potentially other things like generators I'd like to raise the question whether or not its a good solution to just turn every IIFE created by the compiler into async as well? I'd rather see some exploration whether these IIFE are necessary in the first place. I will try to do that when I find some time, but it feels bad to just pollute the whole scope with async fns unconditionally, even if possibly not needed. So either we could do some tracking during analysis if its actually needed, or just get rid of the IIFE in the first place. I mean it would be nice if JS just had support for blocks with return values, but that doesn't seem to be coming anytime soon.
Also kinda worried about the performance implications. a lot of nested extra async/await all over the place probably can't be good performance wise. there can be a lot of IIFE generated and they all then imply one extra promise+await creation
I mean not everything always needs an extra IIFE in all contexts. the analyzer is smart enough to figure out when it actually is, but let for example doesn't always need one.
(let [x (if some-condition (foo) (bar))]
(using x))
let ret123;
if (some-condition) {
ret123 = foo();
} else {
ret123 = bar();
}
x = ret123;
using(x);would be perfectly reasonable code in many contexts I think
This crossed my mind as well. But I think it might be better to do this as a second optimization issue. Existing code isn’t affected by the async / await feature so no regressions there. New async/await code might not be as optimal as it could be, but optimizing let to get rid of IIFE etc is a much bigger scope. Yeah, we can track if something async is happening inside a potential IIFE and only make it async if it needs to be, probably not difficult, but I’d rather do that as a second round once we have the basics in place, unless @dnolen thinks it’s essential.
Btw, isn't Closure clever enough to optimize some of these?
I wonder how stack traces would look like with a bunch of async functions, probably as scary as core.async ones
Try it out. It looks much better from my experience
Just similar to native JS stack traces when writing async/await
man, do-expressions are still in stage 1: https://github.com/tc39/proposal-do-expressions