There are two possible optimizations in current implementation. Given the JS program: ``` class C { static { } static { } } ``` The corresponding emitted bytecode for evaluating class field initializations and static blocks. ``` bb#1 Predecessors: [ ] [ 0] enter [ 1] get_scope dst:loc4 [ 3] mov dst:loc5, src:loc4 [ 6] check_traps [ 7] get_by_id dst:loc6, base:callee, property:0 [ 12] new_func_exp dst:loc7, scope:loc4, functionDecl:0 [ 16] put_by_id base:loc7, property:0, value:loc6, flags:Strict [ 22] mov dst:loc8, src:this [ 25] call dst:loc7, callee:loc7, argc:1, argv:14 [ 31] get_by_id dst:loc6, base:callee, property:0 [ 36] new_func_exp dst:loc7, scope:loc4, functionDecl:1 [ 40] put_by_id base:loc7, property:0, value:loc6, flags:Strict [ 46] mov dst:loc8, src:this [ 49] call dst:loc7, callee:loc7, argc:1, argv:14 [ 55] ret value:Undefined(const0) Successors: [ ] Identifiers: id0 = PrivateSymbol.homeObject Constants: k0 = Undefined ``` where `[ 7] get_by_id dst:loc6, base:callee, property:0` and `[ 31] get_by_id dst:loc6, base:callee, property:0` are redundant. And if the static block is empty, we should not emit the function call bytecode. Maybe we can do these optimizations in another path.
<rdar://problem/100928750>