cljs-dev

thheller 2026-01-19T08:56:00.016449Z

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.

thheller 2026-01-19T08:59:50.079469Z

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

thheller 2026-01-19T09:04:47.276189Z

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.

thheller 2026-01-19T09:05:10.499619Z

(let [x (if some-condition (foo) (bar))]
  (using x))

let ret123;
if (some-condition) {
  ret123 = foo();
} else {
  ret123 = bar();
}
x = ret123;
using(x);

thheller 2026-01-19T09:05:18.654089Z

would be perfectly reasonable code in many contexts I think

borkdude 2026-01-19T09:17:09.360539Z

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.

borkdude 2026-01-19T09:20:44.146959Z

Btw, isn't Closure clever enough to optimize some of these?

Roman Liutikov 2026-01-19T09:33:00.279169Z

I wonder how stack traces would look like with a bunch of async functions, probably as scary as core.async ones

borkdude 2026-01-19T09:38:03.236499Z

Try it out. It looks much better from my experience

borkdude 2026-01-19T09:38:42.902109Z

Just similar to native JS stack traces when writing async/await

shaunlebron 2026-01-19T20:47:40.556999Z

man, do-expressions are still in stage 1: https://github.com/tc39/proposal-do-expressions