godotengine / godot

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

Size of HTML5 exports has increased significantly between 3.x and 4.0.beta #68647

Open netAction opened 1 year ago

netAction commented 1 year ago

Godot version

4.0 Beta 4

System information

Windows 64

Issue description

The HTML5 export of a single empty 2D node has a size of >40MB. Godot 3.5 HTML5 export is already >20MB.

Users on low bandwidth are kept away from the game. The most important advantage of HTML5 over native apps is the easy access. You can start a game via scanning a QR code. But exactly this benefit of HTML5 is weakened in regions like Germany where cellular coverage and wifi quality are low.

The other issue is the CPU load caused by the huge amount of executable code. 40MB JS and WASM code affects the device speed more than a PNG of 40MB. I didn't benchmark this though.

I am aware Godot does come with some basic functionality and WASM wrapper that already needs about 1MB. But the other engine size could be optimized. Maybe a selection of different engines could make sense that are chosen depending on the featured needed for the game.

There are methods for compression of WASM. It can be done by Apache mod_deflate or even the Javascript zlib library pako. This helps a lot but does not shrink the game by a magnitude.

Steps to reproduce

Create a new project. Add 2D node. Export HTML5.

Minimal reproduction project

No response

Zireael07 commented 1 year ago

Related: https://github.com/godotengine/godot/issues/41118 (the first comment mentions the biggest factor is likely the sheer size of the WASM payload)

Related: https://github.com/godotengine/godot-proposals/issues/190 which would be likely closed when https://github.com/godotengine/godot/pull/47054 is merged

Calinou commented 1 year ago

Unfortunately, I don't see much ways to reduce engine binary size compared to what we have now. All the new features in 4.0 come at a cost. Now you know why we try not to bloat the core too much :slightly_smiling_face:

What could be tried to speed up instantiation would be to split the WASM into several files, and try to download and initialize them in parallel. This is easier said than done though.

Maybe a selection of different engines could make sense that are chosen depending on the featured needed for the game.

This is now implemented with feature build profiles, providing you build a custom HTML5 export template.

clayjohn commented 1 year ago

It would be helpful for us to investigate where exactly the extra 20 mbs are coming from. While the size of the engine has certainly increased, it hasn't doubled in size.

Perhaps we are mistakenly including debug symbols or something, or a dependency that wasn't previously exposed to HTML5 builds now is.

On that note, @netAction Could you confirm whether you are using debug or release builds for the HTML5 export?

Calinou commented 1 year ago

One thing we might do for mobile and web platforms is disable TextServerAdvanced by default, as it represents several MBs of binary size (it links against HarfBuzz and all that).

The downside is that support for right-to-left typesetting and complex scripts would be lost in mobile/web by default. It also increases the chance of bugs surfacing only after you export the project to a mobile/web platform (due to a different TextServer being used by default). Users wishing to use TextServerAdvanced on mobile/web platforms would have to compile custom export templates with TextServerAdvanced enabled.

netAction commented 1 year ago

Could you confirm whether you are using debug or release builds for the HTML5 export?

After switching off Debug in Godot 4.0 beta4, the export has 24MB rather than 41MB.

After switching off Debug in Godot 3.5, the export has 13MB rather than 17MB.

Sorry I missed this option.

rthery commented 1 year ago

I'm investigating if Godot could replace my engine of choice for web development (I'd prefer to code in C# than TS) and thought I'd share some insights. The current size of the engine to download is indeed a show stopper for now. The initial download time is crucial in terms of acquisition, so at the moment Godot is not viable professionally. (Which is the same problem with Unity, they tried to solve via their cancelled Tiny initiative, it's a very hard problem to solve for C++ engines)

I just tested Godot 4.0 beta8, I got these results with a release web build with just a cube, a light and a camera 26M Godot.wasm 6.6M Godot.wasm.gz (compressed with gzip) 4.4M Godot.wasm.br (compressed with brotli)

Aiming for something around 1-2M after compression would still be worst than JS based engines (I don't think Godot will ever be able to beat those), but competitive enough to be used professionally for web games :)

Are the feature build profiles already available somewhere in the beta ? I don't understand how to get that window displayed in the PR.

Calinou commented 1 year ago

If file size is critical for you, I would recommend you stick to 3.x but also use GDScript instead of C# (as it removes the need to embed Mono). 3.x will also run better on low-end devices with limited RAM, and it'll remain supported for a while after 4.0 is released.

4.4M Godot.wasm.br (compressed with brotli)

Which compression level did you specify? I don't remember if the Brotli CLI uses the highest compression level of 11 by default. This is recommended for static files as decompression speed is not impacted by the compression level.

I wish browsers started adopting Zstandard, but something tells me that won't happen…

Aiming for something around 1-2M after compression would still be worst than JS based engines (I don't think Godot will ever be able to beat those), but competitive enough to be used professionally for web games :)

Even with an export template compiled after a build profile, I don't think it's possible to get below 3 MB compressed in 4.0 (while 3.x can certainly fit within that size).

Are the feature build profiles already available somewhere in the beta ? I don't understand how to get that window displayed in the PR.

Yes, but you need to compile an HTML5 export template from source to benefit from the generated build profile. You can display that dialog using Project > Customize Engine Build Configuration… at the top of the editor window.

Note that this dialog's automatic detection doesn't automatically disable some features that aren't needed in your project: https://github.com/godotengine/godot/issues/69820

miguelportilla commented 1 year ago

Please excuse my ignorance, I am new to Godot but how do you export to HTML5 with Godot 4? I am using the beta 8 version.

I've downloaded and inspected the export templates zip file and I only see Mac, Linux, and Windows templates.

Thanks

akien-mga commented 1 year ago

You must be using the .NET build, which currently only supports desktop platforms (like .NET Core itself).