Search Issue Tracker

Third Party Issue

Votes

0

Found in

2021.2

2021.2.0b1

Issue ID

1345549

Regression

No

Deserialization of object is very costly in RestoreBackups -> RebuildManagedInstance during Domain Reload

Serialization

-

Reproduction steps:
1. Open attached project "bug_report.zip" and scene "TemplateScene"
2. In Preferences window, enable Diagnostics -> Core -> EnableDomainReloadTimings
3. In Hierarchy window, select "Player" GameObject
4. In Inspector window, open PlayerController.cs component
5. In script editor, make some small change to the script
6. In Profiler window or Editor.log Performance entries, observe the time taken by RestoreBackups -> RebuildManagedInstance

Expected result: The time taken by RebuildManagedInstance is small (<100ms)
Actual result: The time taken by RebuildManagedInstance is significant (>150-1000ms)

Reproducible with: 2021.2.0b3
Could not test with: 2019.4.29f1, 2020.3.14f1, 2021.1.14f1 (no RebuildManagedInstance in Profiler Hierarchy), 2022.1.0a2 (project crashes while opening)

Workaround:
Moving parameters to a separate ScriptableObject fixes the issue, more context here - https://forum.unity.com/threads/any-update-regarding-increased-script-assembly-reload-time.1117138/#post-7236887

  1. Resolution Note (2022.1.X):

    Based on the Diagnostic output the performance cost appears to come from the initialization of static XmlSerializer inside PlayerParameters, each time PlayerController is recreated. When that variable is left as null the RebuildManagedInstance cost disappears. That library is part of .net and not Unity, so we cannot directly speed it up, but perhaps it would be possible to improve domain reload speed by making the initialization on-demand rather than happening each time the assembly is reloaded.

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.