godot: Slow initial instancing in _process()
Godot version: v3.2.beta2 OS/device including version: Intel Core i7-4790K CPU 16GB ram Windows 8.1 64bit
When I measure the time it takes to instance scenes (or do .new()
), under certain circumstances it’s taking much longer in beta2 than beta1. For my computer in beta1 it takes 15ms, in beta2 it’s taking 80ms. It seems subsequent instancing doesn’t have this delay, so there’s a possibility that it’s not a bug at all and just how the engine works in handling initial instances, I wouldn’t know.
This only affects certain nodes:
- MeshInstance with a mesh assigned
- Light2D
- Particles2D
Possibly others, I only tested a dozen or two.
Steps to reproduce: This takes 80ms on my computer:
func _process(delta):
var test = OS.get_ticks_msec()
var id = Light2D.new()
print('Code time: '+str(OS.get_ticks_msec()-test)+'ms')
set_process(false)
This takes 0ms on my computer:
func _ready():
var test = OS.get_ticks_msec()
var id = Light2D.new()
print('Code time: '+str(OS.get_ticks_msec()-test)+'ms')
Minimal reproduction project:
SlowInstancing.zip
Here is a project that tests the speed of instancing MeshInstance scenes subsequently. If you uncomment the text in _ready()
all speedtests will drop to 0ms. I have no idea what’s going on.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (18 by maintainers)
I didn’t call it a regression and give it high priority, that was your interpretation.
This is still true. And weird. So your interpretation of a regression is fine. Don’t let your user error bum you out too much. haha.
You mean beta 1 and beta 2. Nice user error. lol
FINE I MESSED UP BIG TIME I’M CRYING NOW ALL THOSE SPEEDTESTS FOR NOTHING AAAAAAHHHHH
Few important things to note. The issue is in 3.0, 3.1+ and 3.2 beta 2, accordingly it is unlikely that a PR introduced in 3.2 beta 2 is solely responsible.
Second. The fact that it appears only in _process and only in GLES3 makes it seem overwhelmingly likely that it is a shader compile issue.
Shaders are compiled on the first frame that an object is drawn, so when the object is instantiated in _process and drawn for the first time, the shaders have to compile right away. When you instantiate in _ready, the shaders would compile later.
@clayjohn It could be that the shaders take more time to compile initially though, especially since this slowdown is only reproduced on the first instantiation.
Could one of you bisect between 3.2 beta 1 (077b5f6c2c06bb2c0af525ee25f87e0db719f9d2) and 3.2 beta 2 (b7ea22c5d203da1b592a743a4c893de25cd34408)?
Given that it seems to affect rendering-related nodes, I guess it might be a regression from changes to rendering code. Might be good to check if it happens only with GLES3 or also with GLES2.
Can confirm on Windows 10.
Using
_physics_process
results in ~0.0 delay.Without ready I still have very similar times:
Seems that the problem occurs only on Windows