So one of the worst and most pointless performance penalties in il2cpp are the static variable checks at the top of functions:
IL2CPP_EXTERN_C IL2CPP_METHOD_ATTR AxisControl_tD6613A2445A3C2BFA22C77E16CA3201AF72354A7* FastTouchscreen_Initialize_ctrlTouchscreentouch2deltaright_m41BF07FF5552D28B90B9241BD75DAC08516CCC29 (FastTouchscreen_t283B7BBFB4762C6E85B0582C5547D08D666BFED7* __this, InternedString_t8D62A48CB7D85AAE9CFCCCFB0A77AC2844905735 ___0_kAxisLayout, InputControl_t74F06B623518F992BF8E38656A5E0857169E3E2E* ___1_parent, const RuntimeMethod* method)
{
static bool s_Il2CppMethodInitialized;
if (!s_Il2CppMethodInitialized)
{
il2cpp_codegen_initialize_runtime_metadata((uintptr_t*)&AxisControl_tD6613A2445A3C2BFA22C77E16CA3201AF72354A7_il2cpp_TypeInfo_var);
il2cpp_codegen_initialize_runtime_metadata((uintptr_t*)&InputStateBlock_t0E05211ACF29A99C0FE7FC9EA7042196BFF1F3B5_il2cpp_TypeInfo_var);
il2cpp_codegen_initialize_runtime_metadata((uintptr_t*)&_stringLiteralA74F11BB6632DDE7D6577D711E3C10FB4B304972);
il2cpp_codegen_initialize_runtime_metadata((uintptr_t*)&_stringLiteralB1E5119D36EC43B340C0A0DDC99F1156546EA9DF);
s_Il2CppMethodInitialized = true;
}
In our codebase, there are 59,350 such checks. Obviously this could be done once at start up, and the static check in every function removed.
In Il2CPP.Api.Output.xml in the il2cpp folder, there’s a list of il2cpp command line arguments that includes:
EnableLazyStaticConstructors
This seems to be off, as confirmed by the il2cpp output folder’s analytics.json only containing one option: EnableInlining.
Just to confirm - I tried using PlayerSettings.SetAdditionalIl2CppArgs(addlArgs); to add EnableLazyStaticConstructors, and it had no effect on the number. So it seems as though EnableLazyStaticConstructors is always on?
This is on Unity 2022.3.19f1.
Does anybody know how to move these static calls out so they’re initialized on startup?