godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.84k stars 20.15k forks source link

Why HTML export loads in a cascade of copies of dependencies? #84996

Open PeterMarques opened 10 months ago

PeterMarques commented 10 months ago

Godot version

4.1

System information

web

Issue description

When loading a godot project on the web, there is the endpoint, the html file, that calls the main javascript file, that coordinates all the wasm bootstrap.

That bootstrap loads several instances of the same file, in a cascade, and that is proved on the http server because the files are re-requested indeed.

What i argue is that if, it is really needed to have all that instances, to do that locally as copies of the already first instance downloaded, or, to download then concurrently, to improve the loading flow.

Because of the cascade nature, it only finishes loading when all load after linear sucessive serie.

If i am correct and there is a way to improve in that direction, we can for sure have at least a 50% load speedup.

image

Well?

Steps to reproduce

Load a html export and inspect the network

Minimal reproduction project

Any

Faless commented 8 months ago

Godot on the web creates a pool of (8) threads (web workers). This is important because creating a thread is an asynchronous operation on the web (as opposed to any other platform).

Each worker thread needs to fetch the code it will be running (index.worker.js), and the module support code (index.js).

You can mitigate this by supplying cache headers from your web server, or enabling the PWA export options (which intercepts fetch requests and provide caching via its service worker).