OdinEditor.OnEnable and OdinEditor.OnDisable gets called more and more times after compilation, causing death spiral in compilation time

Issue #927 invalid
Jonathan Hertz created an issue

1. What happened?

After using the editor for some minutes, script compilation becomes slower and slower. Deep profiling showed OdinEditor.OnEnable and OdinEditor.OnDisable gets called thousands of times, with this number increasing a lot after each script compilation. This will very quickly cause each script compilation to take several minutes, and get slower and slower.

2. How can we reproduce it?

Open the attached project and enter playmode. Note the time script compilation takes. Exit playmode, select ScriptableObject/CannonBall, wait a couple of minutes, and enter playmode. Note the difference in script compilation time. Waiting longer will keep making compilation slower. When deep profiling you should see calls to OdinEditor.OnEnable and OdinEditor.OnDisable start to rack up.

The same issue does not appear when Odin Inspector is not installed. (I tested by deleting the plugins folder).

3. If screenshots would help explain or demonstrate your issue, please include these.

4. What version of Unity are you using?

2021.3.25f1

5. What version of Odin are you using? (See "Tools > Odin Inspector > About")

3.1.12.3

6. Do you have Editor Only mode enabled?

No

7. What operating system are you on?

Windows 10

Comments (1)

  1. Tor Esa Vestergaard

    I took a look at the repro project, and this is not an Odin bug, but a bug in a custom editor in the project itself.

    The issue here is that there is a custom editor for DataCannonBall which, in the DrawConditions method, calls CreateEditor. This call happens every single GUI event, creating a new editor instance every time, and will start stacking up many tens of thousands of editor instances without ever cleaning up after itself.

    Editor instances should be cached, and then destroyed when they are done being used - they should not be created anew every frame. This issue is also present without Odin in the project, but since Unity's default editor has no OnEnabled code, it was not as clearly visible - but with or without Odin, many thousands of editor instances are being created in the background and never being destroyed.

  2. Log in to comment