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
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
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Out-of-bounds memory access with multiple CanvasRenderers under a Canvas when using Mesh API
- Inspector tries to access file after it was deleted when the file was locked in Inspector window
- Changing Transform values in Search window Inspector loses focus while dragging and stopping mouse without releasing dragging action
- Saving changes on the dirty VFX Graph during the Play mode throws "The referenced script (Unknown) on this Behaviour is missing!" warnings
- VFX Graph Debug Info overlaps the "Initialize" block debug info by default
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.