+1 vote

Hi,

I have a script that is attached to a single node in multiple scenes, that appears to cause a slow down on the browser (html5) build of the game.

As this script currently initialises during run time, I was wondering if it was possible in godot to make this occur during build time which would improve overall performance and if so how I could implement it.

The initialise function of this script is largely static, which it only being different on different scenes due to what is within the node. The node itself will never have it's children modified via script.

I've attempted to search regarding this, but haven't found anything overly helpful for me.

in Engine by (13 points)

1 Answer

0 votes

Compile-time (or "build-time") object initialization is not a thing, in any language. Though if you want to take advantage of some compile-time optimization, the best thing would be to rewrite your script in C++.

What does your node's _ready method do exactly? Could you post your code?

When does the slow down happen? Only once when the scene is first loaded? If not, then I don't think the slowdown comes from the initialization. Please post the whole script.

by (1,086 points)

In general the script traverses all tiles within a 3d gridmap and generates an astar graph.

Further examination makes it appear that the slowdown is due to either rendering or environment file as the above _ready function logs fairly quickly when the scene starts.

In terms of compile time initialisation, I was wondering if as an optimisation step it was possible able to compute this astar graph on build as a static array and then utilise that static data instead of looping through the tiles.

Will further look into the exact cause of the slowdown, I just assumed the above would be a good optimisation step if it was possible.

I see. Well if the gridmap is static you could always "bake" the a-star graph. By that I mean make a tool script that writes the graph to a json file or something, and when loading the scene instead of computing the graph you read it from the file.

Have you tried using the profiler? That could help you determine if slowdowns happen in one of your own functions.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.