Search Issue Tracker

Postponed means that the issue was either a feature request or something that requires major refactoring on our side. Since that makes the issue not actionable in the close future we choose to close it as Postponed and add it on our internal roadmaps and technical debt pages instead.

Postponed

Votes

6

Found in

2018.4

2019.1.14f1

2019.2

2019.3

2020.1

Issue ID

1196501

Regression

No

[IL2CPP] Static constructors cause unnecessary wait time, s_Il2CppMethodInitialized and IL2CPP_RUNTIME_CLASS_INIT checks

IL2CPP

-

How to reproduce:
1. Open attached project "" and scene ""
2. Select IL2CPP scripting backend (Project settings -> Other Settings -> Configuration -> Scripting BackEnd -> IL2CPP)
3. Increase fps lock limit in script (Hierarchy window -> NvidiaCounter -> Max Framerate -> 9999)
4. Make sure Line 22 in "StaticMethodCallTestBehaviour" is not commented (returns Vector3.Dot)
5. Build and run project
6. Observe fps counter (around 33 on my pc)
7. Repeat steps 4-6 with line 23 uncommented
8. Observe fps counter (1100-2100fps, depending on the versions)

Expected result: Vector3.Dot in a static method does not take up time (s_Il2CppMethodInitialized bool check and IL2CPP_RUNTIME_CLASS_INIT macro) resulting in step 6, more fps
Actual result: Vector3.Dot in a static method does take up time (s_Il2CppMethodInitialized bool check and IL2CPP_RUNTIME_CLASS_INIT macro) resulting in step 6, low fps

Reproducible with: 2018.4.12f1, 2019.2.12f1, 2019.3.0b10, 2020.1.0a12
Could not test with: 2017.4 (IL2CPP not implemented)

  1. Resolution Note:

    We're treating this as a feature request. It would still be a nice optimization to implement.

Comments (4)

  1. IgorBoyko

    Apr 05, 2023 13:25

    Is there any link to test project to thoroughly inspect the problematic code? I'd like to compare it to our project to evaluate the impact

  2. Kamyker

    Aug 11, 2021 03:03

    This got implemented from what I know.

  3. Vincenzo

    Apr 06, 2020 10:30

    This is not a feature request, this is an massive problem with IL2CPP in many normal code cases that needs to be fixed, static constructors are used throughout for Math and other such things. this is not acceptable.
    This has to be fixed ASAP. and backported to the LTS versions.

  4. Kamyker

    Feb 14, 2020 16:11

    Also makes Unity.Mathematics package very slow as mentioned in https://forum.unity.com/threads/unity-mathematics-available-on-github.526100/page-7#post-5480892

    sin is ~15 times slower than (flaot)Math.Sin

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.