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

HTML5 export for Godot 4.x takes 1-2 minutes to load on macOS #70691

Open
Luzzotica opened this issue Dec 29, 2022 · 75 comments
Open

HTML5 export for Godot 4.x takes 1-2 minutes to load on macOS #70691

Luzzotica opened this issue Dec 29, 2022 · 75 comments

Comments

@Luzzotica
Copy link

Luzzotica commented Dec 29, 2022


Bugsquad note: This issue has been confirmed several times already. No need to confirm it further.
Bugsquad note2: Also, please avoid asking when this will be fixed. The issue is confirmed to be with the version of ANGLE used by Chromium, so we are all waiting for Google to ship the fix.


Godot version

4.0.beta10

System information

MacOS Monterey 12.2.1

Issue description

Godot games block the main thread (And potentially crashes it) on MacOS.

Untested for Windows or Linux.

This happens from both a generic build and when you run the project in a browser from the engine.

Steps to reproduce

Create a new project for Godot Beta 10.

Add a UI Button to the screen.

Have it print things out, whatever you wish.

Add an HTML5 export, install the HTML5 export library if necessary.

Click the run on HTML5 button on the top right.

Proceed to wait for 1-2 minutes before the game will fully load.

Minimal reproduction project

TestGodot4Web.zip

@Calinou

This comment was marked as outdated.

@Calinou Calinou closed this as not planned Won't fix, can't repro, duplicate, stale Dec 29, 2022
@Luzzotica
Copy link
Author

@Calinou I feel like this isn't the same as those. I don't believe it's a size issue.

Running locally on MacOS on both Brave and Chrome: Took about ~2 minutes and 30 seconds for the game to load. Both Brave and Chrome wanted to kill the tab. It had locked up the entire browser for (Couldn't go to any other tab).

Running this on Windows, and the game loads in ~10 seconds.

If this is a size issue, then MacOS Chrome and Brave are just INSANELY slow to load things. Which doesn't seem right.
Also, since I'm running it locally, I assume the web assembly can load faster... This might be untrue, but I doubt that it is.

@Zireael07
Copy link
Contributor

In that case, it might be shader loading and/or conversion (correct me if I'm wrong, but MacOS converts stuff to ANGLE behind the scenes, doesn't it?)

@Calinou Calinou reopened this Dec 29, 2022
@Calinou Calinou changed the title HTML for Godot Beta 10 Takes 1-2 Minutes to Load on MacOS HTML for Godot 4.0.beta10 takes 1-2 minutes to load on macOS Dec 29, 2022
@Calinou Calinou changed the title HTML for Godot 4.0.beta10 takes 1-2 minutes to load on macOS HTML5 export for Godot 4.0.beta10 takes 1-2 minutes to load on macOS Dec 29, 2022
@clayjohn
Copy link
Member

clayjohn commented Jan 2, 2023

In that case, it might be shader loading and/or conversion (correct me if I'm wrong, but MacOS converts stuff to ANGLE behind the scenes, doesn't it?)

I also think may be a shader compilation issue. Chrome definitely uses ANGLE, but I am not sure about Brave. macOS doesn't use ANGLE when running on desktop though.

While attempting to fix the gl_compatibility renderer on macOS I experimented with using ANGLE, but found that the shader compilation times ended up increasing by over 100X. In #70065 I was able to speed up shader compilation times and get gl_compatibility working on macOS without ANGLE. However, since chrome uses ANGLE, my guess is we are hitting those pathological shader compilation issues anyway. I am not sure what exactly in the shader is causing the issue (it may even be a bug in ANGLE).

@bergice
Copy link

bergice commented Jan 10, 2023

Related #65696

@thomasbergersen
Copy link

The issue of Chrome crashing on MacOS 13 does indeed exist, and Firefox takes over 2 minutes to load.

@shinspiegel
Copy link

I'm completely new to C++ dev, but I would like to help with this issue.
What can I do to help?

@Luzzotica
Copy link
Author

Can confirm, 4.0 RC2 is still taking minutes to load on Brave on MacOS.. Causes my entire browser to lock down completely.

@dhnm
Copy link

dhnm commented Feb 27, 2023

The issue still persists in rc4, rc5, rc6. In Forward+, Mobile, and Compability mode. Chrome hangs, Firefox takes a while but loads, and Safari has a infinitely loading spinner and reports the following in the console:

[Error] Unhandled Promise Rejection: CompileError: WebAssembly.Module doesn't parse at byte 1155: can't get 1th argument Type
	promiseEmptyOnRejected
	promiseReactionJob
> Selected Element
< <html lang="en">…</html>
[Error] still waiting on run dependencies:
	onPrintError (tmp_js_export.js:14008)
	(anonymous function) (tmp_js_export.js:737)
[Error] dependency: wasm-instantiate
	onPrintError (tmp_js_export.js:14008)
	(anonymous function) (tmp_js_export.js:739)
[Error] (end of list)
	onPrintError (tmp_js_export.js:14008)
	(anonymous function) (tmp_js_export.js:742)

@mgc8
Copy link

mgc8 commented Aug 1, 2023

It should, and from testing it does appear to set the right headers, but for some reason when loaded through itch.io the app still doesn't "see" them. Could be due to being inside an iFrame, or a conflict between the headers set by itch.io and the ones set in JavaScript?

After some thorough testing, I think I tracked down the issues with itch.io (there were two):

  1. coi-serviceworker.js itself has a bug that reverses the 'credentialless' and 'request-corp' options, thus (sigh) only affecting Safari, since Chrome and Firefox work with either one; reported here

  2. itch.io complicates the header situation due to the way the "game" pages are configured:

  • If the "experimental SharedArrayBuffer" option is not selected, the main page will have no headers, while the iframe can set them fine (such as with our service-worker script), but the browser will not activate the "crossOriginIsolated" status because the parent container needs to have it as well. If the main page had been loaded on the same domain as the iframe, this would not have been an issue, since the service-worker would have taken that over as well (tested locally) and overridden the headers. But on itch.io they are on different hostnames, thus an iframe service-worker can't touch the parent.
  • If the experimental option is selected, then the main page will have headers, but hardcoded to 'credentialless'; meanwhile, the iframe can override its own headers with the service-worker and send the correct ones for each browser (i.e. 'credentiallless' for Chrome and 'request-corp' for Safari). This will work fine in Chrome or Firefox, but Safari doesn't see the parent page as being properly isolated due to the 'credentialless' there, which our service-worker again cannot override; thus it breaks.

So, for now, the "open iframe in its own tab/window" option remains as a workaround, while itch.io could improve the situation by adding a bit of browser-detection code to switch between 'credentialless' and 'request-corp' as needed, though I'm not sure if they have any inclination to do that.

@fguillen
Copy link

fguillen commented Aug 1, 2023

Thanks @mgc8, all this is great support for all the suffering mac Godot users like me

@mgc8
Copy link

mgc8 commented Sep 9, 2023

I'm not sure why it disappeared, but I can confirm that the Chrome flags suggestion posted earlier works great in Chrome 116.0.5845.179/macOS/M1, and is an easier temporary workaround rather than the Terminal version of the same (at least until the Chrome devs make Metal the default):
Screenshot 2023-09-09 at 21 50 47

@leafo
Copy link

leafo commented Oct 5, 2023

So, for now, the "open iframe in its own tab/window" option remains as a workaround

On itchio, you should assume that at some point your game will be required to be loaded in an iframe that has been generated by itch.io. A solution that involves breaking out the frame is not a long term fix because we have system in place to automatically inject site locking to prevent shady third-party platforms from embedding our games to steal bandwidth.

while itch.io could improve the situation by adding a bit of browser-detection code to switch between 'credentialless' and 'request-corp' as needed

Unfortunately require-corp has a bunch of side effects with regards to any external references on the page, and may impact how the site operates, so the solution isn't simply change the value of the header. This is why we opted for credentialless since it's mostly transparent solution, but the browser compatibility is not ideal.

I think our long term fix (assuming safari never supports the header) will probably involve launching the game in a separate page containing only an iframe and different headers specific to safari, instead of trying to execute the game on the full project page.

Edit: Was double checking the code and it looks like this was already implemented for the Game Embed tool located in the uploader's dashboard. If they generate an embed URL from there, it will provide a link to the game that will use require-corp instead of credentialless. Example game URL: https://itch.io/embed-upload/8831158?color=1e0e11 (note url may not work in the future if this particular developer removes their game)

Edit2: I deployed a fix that will cause Safari to always load games in a new window using the embed URL I described above that uses the require-corp header value. Should resolve any issues for Safari users, at the expense of slightly different user experience.

@transmutrix
Copy link

transmutrix commented Oct 5, 2023

On Newgrounds, SharedArrayBuffer support works in Safari as well as the other major browsers (tested with the same build of the same project, etc.). I'm not sure which method they've used, however, or if it would translate easily to itch, if it would be useful to look into, or who over there to ask about it if it would be useful.

Edit: I should note my test wasn't with a Godot game, but a plain jane Emscripten build of a C program—the underlying issue appears to be the same.

@mgc8
Copy link

mgc8 commented Oct 6, 2023

Edit2: I deployed a fix that will cause Safari to always load games in a new window using the embed URL I described above that uses the require-corp header value. Should resolve any issues for Safari users, at the expense of slightly different user experience.

Hi @leafo, thank you for dropping by! This looks like a good, pragmatic solution given the current state of browsers, with every major one seemingly having a different, incompatible issue related to this. I can confirm that the "new window" works nicely for itch.io games in Safari, so at least that's solved now for end-users. Hopefully the browser developers will also move on with updates/fixes to make the whole process less frustrating for both site owners and game devs (three months later, Chrome still hasn't switched to Metal as default back-end on macOS)...

@transmutrix
Copy link

transmutrix commented Oct 7, 2023

The "new window" solution works great on desktop! On mobile, it gives me a 404 error in the new tab (tried iOS and iPadOS, both Safari and Chrome, but did not try Android).

@kamko0
Copy link

kamko0 commented Nov 8, 2023

As of right now me using IOS doesn't seem to load my game that used Godot4, so even with the Embed game link it doesn't work.
Not sure if there will be a fix anytime soon but at least it works on pc for now.

@revanj
Copy link
Contributor

revanj commented Nov 20, 2023

Hi there @leafo , thank you so much for the fix and for creating the website indie devs know and love!

In recent exports, the new window in safari appears to give 404. This seems to indicate that the generation of the embed link is not working correctly. Is there anything users can do to specify the embed link, or otherwise make the new window use the correct embed link? This is on a laptop M1 Mac.

@leafo
Copy link

leafo commented Nov 20, 2023

@revanj

In recent exports, the new window in safari appears to give 404. This seems to indicate that the generation of the embed link is not working correctly. Is there anything users can do to specify the embed link, or otherwise make the new window use the correct embed link? This is on a laptop M1 Mac.

Is your safari configured to block cookies in any way? A cookie is combined with the generated link to verify access to the popup

@tavurth
Copy link
Contributor

tavurth commented Nov 28, 2023

@revanj

In recent exports, the new window in safari appears to give 404. This seems to indicate that the generation of the embed link is not working correctly. Is there anything users can do to specify the embed link, or otherwise make the new window use the correct embed link? This is on a laptop M1 Mac.

Is your safari configured to block cookies in any way? A cookie is combined with the generated link to verify access to the popup

My safari is fresh out of the box and shows the same issue.

Screenshot 2023-11-28 at 22 21 01

@adamscott adamscott changed the title HTML5 export for Godot 4.0.beta10 takes 1-2 minutes to load on macOS HTML5 export for Godot 4.x takes 1-2 minutes to load on macOS Dec 11, 2023
@adamscott
Copy link
Member

It seems to be way better when exporting using the single-threaded export template. #85939

@Morpheu5
Copy link

Maybe on Chrome, but now it takes forever on Firefox/macOS.

@nickarora
Copy link

As an update, it does appear that Chrome is now using the Metal renderer by default now. I am using Chome 123.0.6312.59 and I have verified that the Angle Metal renderer is being used. I have not changed any flags or set a custom profile.

Also the "image rendering issue" renders without issue.
https://arturitoproductions.itch.io/testingimageissue (password: godot)

I also use Brave but it still not updated to use the Angle Metal Renderer. I suspect its only a matter of time for the other browsers to follow suit.

@clayjohn
Copy link
Member

As an update, it does appear that Chrome is now using the Metal renderer by default now. I am using Chome 123.0.6312.59 and I have verified that the Angle Metal renderer is being used. I have not changed any flags or set a custom profile.

Also the "image rendering issue" renders without issue. https://arturitoproductions.itch.io/testingimageissue (password: godot)

I also use Brave but it still not updated to use the Angle Metal Renderer. I suspect its only a matter of time for the other browsers to follow suit.

Thank you very much for updating us! I suspect firefox and brave should update soon to match, but I worry that safari is still a long ways off. At any rate, having everything work well on the others puts us in a much better position.

@tavurth
Copy link
Contributor

tavurth commented Mar 27, 2024

Also the "image rendering issue" renders without issue. https://arturitoproductions.itch.io/testingimageissue (password: godot)

That demo locks up my Chrome, but no longer locks up my computer.

It will sit there like this for a long time:
Screenshot 2024-03-27 at 10 03 43

Screenshot 2024-03-27 at 10 05 04 Screenshot 2024-03-27 at 10 06 10

Interesting that this appears to be a CPU bound issue, why is that?

@nickarora
Copy link

@tavurth The screenshot you posted indicates you need to relaunch Chrome for chrome version you've listed to take effect. I might try relaunching chrome and trying again. The other difference is that I am using an ARM (M1) machine, but I can't see why that would matter.

Once you've restarted Chrome, can you open the console and run the following commands and share the output:

const gl = document.createElement("canvas").getContext("webgl");
const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);

FWIW, on my machine, I see:

ANGLE (Apple, ANGLE Metal Renderer: Apple M1 Pro, Unspecified Version)

@chrissearle
Copy link

chrissearle commented Mar 27, 2024

That's interesting. Can I ask what chrome version?

Looks like its M* related though - I have what chrome says is latest as of today: 123.0.6312.87 on an intel macbook pro and a M3 macbook pro and I get:

Intel: ANGLE (ATI Technologies Inc., AMD Radeon Pro 5300M OpenGL Engine, OpenGL 4.1)

M3: ANGLE (Apple, ANGLE Metal Renderer: Apple M3 Max, Unspecified Version)

@starry-abyss
Copy link
Contributor

On my M1 laptop the build with a few number labels from here https://arturitoproductions.itch.io/testingimageissue opens quickly on Chrome, but slowly on Firefox. And on Safari it's popping up a new itch.io window, which gives a 404 error :)

@nickarora
Copy link

nickarora commented Mar 27, 2024

Firefox has likely not adopted the Angle Metal renderer as their default yet.

It may be the same with the latest version of non-ARM Chrome installs. If the x86 (intel based) installs of chrome are not yet defaulted to Angle Metal renderer, then we'll have to wait a bit longer for Godot 4 web exports to work as expected for all mac users. As of today, it should be working for M1, M2, M3 mac users with the latest version of chrome

I believe the Safari 404 issue is unrelated (there's some discussion above about a missing required header on itch.io)

@tavurth
Copy link
Contributor

tavurth commented Mar 27, 2024

The screenshot you posted indicates you need to relaunch Chrome for chrome version you've listed to take effect

Yep, was just keeping the version the same as you listed in your original post. Now it's:

Screenshot 2024-03-27 at 23 02 58

And the result of the GPU probe:

'ANGLE (Intel Inc., Intel(R) Iris(TM) Plus Graphics 655, OpenGL 4.1)'

@nickarora
Copy link

It appears the new chrome default has only been applied to ARM based macs. intel based macs may have to wait a bit longer. Still, it's promising that these changes are slowly trickling out

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