Edoardo Luppi
04/12/2026, 4:03 PMcompanion object because every operation that reaches into that companion checks for its initialization.
For example, a compiled JS constructor might end up being:
constructor(a, b) {
Companion_getInstance();
this.a = a;
this.b = b;
}
where Companion_getInstance() is:
function Companion_getInstance() {
if (Companion_instance === VOID)
// Omitted Instantiation
return Companion_instance;
}
Now with companion blocks, as far as I understand from §4.2.1, properties declared under companion { ... } will translate to proper statics, and not to another lazily initialized instance attached to the outer declaration.CLOVIS
04/12/2026, 5:14 PM=== VOID really create a measurable performance difference?Edoardo Luppi
04/12/2026, 5:16 PMArtem Kobzar
04/13/2026, 5:44 AMEdoardo Luppi
04/13/2026, 7:50 AMArtem Kobzar
04/13/2026, 9:07 AMdeferred imports for this purpose and eliminate all top-level and static initializers.Edoardo Luppi
04/13/2026, 9:38 AMdefer, I guess it becomes an ESM target only feature tho, as - if I understood correctly what you want to do - that requires per-file.Edoardo Luppi
04/13/2026, 9:40 AMEagerInitialization (or the addition of a new annotation prefixed with Js*).