Facepunch / sbox-issues

176 stars 12 forks source link

Prefabs containing ActionGraphs take much more time to spawn #6357

Closed Rylius closed 3 weeks ago

Rylius commented 1 month ago

Describe the bug

Cloning prefabs which contain action graphs is significantly slower than identical prefabs without the graph.

Ran into this in my game jam project when I implemented a shotgun spawning 10 projectile prefabs at once, which made the game stutter. Worked around it by moving the graph to code, which wasn't exactly ideal.

To Reproduce

actiongraph_slow_clone_repro.zip

There's two objects spawning a 1000 prefabs each. The prefabs are identical, but only one of them contains an action graph. (The action graph itself is nonsensical and doesn't even get executed.)

Spawning GameObject:prefab_with_action x1000 took 1068.3133ms (avg 1.0683133ms)
Spawning GameObject:prefab_without_action x1000 took 53.749ms (avg 0.053749000000000005ms)

It gets even worse with larger action graphs. Just duplicating all nodes twice makes it take over 3 seconds in this example.

Expected behavior

Cloning prefabs with action graphs shouldn't take this much longer.

Media/Files

image image

Additional context

No response

Metapyziks commented 3 weeks ago

Pushed some changes that help this a bit, I'll see what else I can do:

Spawning [GameObject:prefab_with_action](arg:0) x1000 took 173.0877ms (avg 0.1730877ms)
Spawning [GameObject:prefab_without_action](arg:0) x1000 took 29.7203ms (avg 0.0297203ms)
Metapyziks commented 3 weeks ago

I think there's no more easy wins so I'll close for now.