Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
netAction opened this issue Nov 14, 2022 · 10 comments
Open

Comments

@netAction
Copy link

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
Copy link
Contributor

Related: #41118 (the first comment mentions the biggest factor is likely the sheer size of the WASM payload)

Related: godotengine/godot-proposals#190 which would be likely closed when #47054 is merged

@Calinou Calinou changed the title HTML5 Export >40MB Size of HTML5 exports has increased significantly between 3.x and 4.0.beta Nov 14, 2022
@Calinou
Copy link
Member

Calinou commented Nov 14, 2022

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 🙂

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
Copy link
Member

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
Copy link
Member

Calinou commented Nov 14, 2022

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
Copy link
Author

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
Copy link

rthery commented Dec 9, 2022

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
Copy link
Member

Calinou commented Dec 9, 2022

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: #69820

@miguelportilla
Copy link

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
Copy link
Member

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

@indubitablement2
Copy link

indubitablement2 commented Sep 23, 2024

Could something like Defold's build server help by allowing less experienced users to remove parts of the engine they don't use?

https://defold.com/manuals/extensions/#the-build-server

They are emscripten based as well and are able to get down to <1MB for simple game like pong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants