Open fishythefish opened 3 years ago
See #48442 for an example where we can't evaluate map and set literals eagerly.
It might be useful to decouple the lazy/eager analysis from the scope visitor. The scope visitor is too early to make a good decision. Probably the best point is in SSA just before generating JavaScript for the initializer, as the execution cost and implicit side-effects will then be most apparent. This deferred decision would need support at link-time, with the lazy static load being generated as a deferred JavaScript expression that is then finalized as a property or variable access for the eager case, or a call for the true lazy case.
The scope visitor currently yields an
EvaluationComplexity
oflazy
for many non-constant AST nodes, regardless of their internal details. In some cases, this pessimizes code because the overhead of the lazy evaluation mechanism dwarfs the cost of eagerly evaluating the initializer. We should investigate where improvements can be made./cc @rakudrama @johnniwinther