inkgd icon indicating copy to clipboard operation
inkgd copied to clipboard

Performance issues when building the container hierarchy

Open ephread opened this issue 6 years ago • 3 comments

Building the container hierarchy of The Intercept currently takes about 2 seconds on my MacBook Pro. This is insanely slow.

  • [x] Check the performances of other implementations (original C#, inkjs).
  • [x] Document the best way to offload the story setup to a background thread.
  • [ ] Find a way to improve the performances.

Edit:

  • The container hierarchy is usually built between 50 and 75 ms in other implementations.
  • The creation of Diverts and Choices seems to create most expensive individual calls (between .05ms and .6ms). The first call to NativeFunctionCall (building the list of available native calls for the Story) is also very expensive (~ 2ms).
  • At the moment, all scripts required by an object are loaded during the init phase; I suspect this is one of the reasons for the poor performance during instancing. It may make sense to defer loading the scripts (even if they are cached) during the actual execution of the story (at the cost of, perhaps, slightly worse performance during execution).
  • Another expensive thing is Path creation (notably used in Diverts and Choices).

ephread avatar May 24 '19 10:05 ephread

Update: It's down to 1.5 seconds with Godot 3.2 and a couple of small optimisations.

ephread avatar Apr 11 '20 20:04 ephread

just reiterating what I asked on Discord: currently my story takes several seconds to load due to building container hierarchy.

Could it be possible to save the container hierarchy in some way (as a packedscene?) to speed this up for release?

2shady4u avatar Jul 05 '20 12:07 2shady4u

Here's my reply on Discord back then for the sake of clarity. Maybe that can rekindle the discussion:

I'm not too familiar with PackedScenes, is it a memory dump of an entire node/object hierarchy? The current bottleneck is not loading he json (it's fairly fast), but instanciating the entire container hierarchy. Unless packed scenes just load binary data directly to the memory, the performance gain might be limited.

I'm a bit stuck in terms of performances, because GDScript is overall slow (the code could probably be written in a more idiomatic way, but I'm not certain it would significantly improve performances). I have a stale branch with a minimal profiler, but I wasn't able to make much progress then

ephread avatar Jan 25 '21 00:01 ephread