Low FPS on mobile browser until suspend resume

389 views
Skip to first unread message

LJA

unread,
Mar 6, 2017, 5:33:51 AM3/6/17
to emscripten-discuss
I'm trying to compile my game for browser using emscripten, SDL2 + OpenGL. On desktop everything seems pretty fine but on mobile I get low fps. Suddenly I noticed the fps jumped back to 60 after I suspended and resumed the browser/page. I have reproduced the same issue on iOS chrome, iOS safari and saw it happening once on android chrome.

I'm guessing this has something to do with the update rate the browser chooses for the game. It could run much faster but the browser chooses a low fps. Might be because of a big lag spike during asset loading. I've tried to narrow this down but haven't found anything conclusive.

Any ideas? I can try to create a repro case if this sounds completely alien.

Floh

unread,
Mar 6, 2017, 11:28:23 AM3/6/17
to emscripten-discuss
I'm seeing a similar behaviour (fluctuating or low frame rate) on my 8-bit emulator which is quite CPU heavy on mobile browsers (http://floooh.github.io/virtualkc/), both on iOS Safari (which is generally quite slow), and Android Chrome (which has a fluctuating framerate), in the emulator is definitely the CPU load which is the problem though. I haven't bothered yet to find out what's the exact issue (for instance the emulator might have pretty big function bodies for the Z80 and 6502 instruction decoder, but I'm using outlining to reduce those).

My smaller Oryol which don't do much CPU work and don't have many WenGL draw-calls run much better on mobile.

I can't offer a solution, just wanted to let you know that you are not alone seeing low performance on mobile ;) My guess is that the Javascript engines haven't been optimized as well for ARM as for x86, or that there are other factors (CPU cache sizes?) in play where ARM has a disadvantage. Not to mention that iOS Safari in general seems to lag behind the other browsers.

I know that a lot of mobile games that could run at 60fps are restricting the framerate to 30fps to get better battery live, so may be it's a good idea in general to aim for 30fps instead of 60 on mobile.

Cheers,
-Floh.

LJA

unread,
Mar 7, 2017, 2:55:10 AM3/7/17
to emscripten-discuss
I'm not sure you read the whole message. The FPS is low (around 10) until I suspend and resume the page. Then I suddenly get 60fps.

Floh

unread,
Mar 7, 2017, 5:53:00 AM3/7/17
to emscripten-discuss
Haven't seen this specific behaviour yet. Does the device get warm while it's running at low fps? Did you try remote-profiling the code while it's running slow via desktop Safari? Any messages on the remote JS console in desktop Safari?

Cheers,
-Floh.

LJA

unread,
Mar 7, 2017, 11:05:09 AM3/7/17
to emscripten-discuss
I tried remote profiling thanks to your suggestion. Didn't know it was this easy.
The results are interesting. Game is running at 3fps, but when I start a timeline recording, fps jumps to 60. When I stop the recording, fps goes back to 3.
Can't see anything weird in the logs.

It seems like the browser is limiting the frequency of animation frame events, but during profiling it forces it to 60.

Why is the browser so stupid? Can I manually affect it? I've tried both
emscripten_set_main_loop(loop, 0, 1);
and
emscripten_set_main_loop(loop, 60, 1);
(with primary focus on the first approach, which is highly recommended). 
Neither one works.

Alon Zakai

unread,
Mar 7, 2017, 1:58:57 PM3/7/17
to emscripten-discuss
Which browser it that? It could be a bug. Or, perhaps there is other CPU activity preventing it from running the event. Closing and opening the browser might affect that (if there were other tabs open, for example).

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Johannes Ahvenniemi

unread,
Mar 7, 2017, 2:19:23 PM3/7/17
to emscripte...@googlegroups.com
iOS Safari. Again, repeating myself, fps goes to 60 after I suspend and resume the browser. After refreshing the page the fps is low again (until suspend and resume, just like I explain already in the topic).

Sent from my iPhone
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/Agj-M1C6YzY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.

Alon Zakai

unread,
Mar 7, 2017, 2:25:05 PM3/7/17
to emscripten-discuss
I see. Yeah, that definitely sounds like a Safari or WebKit bug to me. You said you may be able to create a repro, if so, please post it here so people can test (and probably we should file it as a WebKit bug).

To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/Agj-M1C6YzY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Rang

unread,
Nov 7, 2017, 9:34:21 PM11/7/17
to emscripten-discuss
Hello,

I've been running into this same issue when porting some games to run in mobile browser. Has there been any update to this? The games seem to run fine on android browsers but on mobile Safari, I have the same low fps, which goes higher upon suspending and resuming the browser. The device does get hot when this is happening, so it must be doing something. Reducing the amount of memory my games use does seem to help mitigate this issue (the frame rate doesn't drop as low) but it still occurs. I can't say for certain if the issue is memory related but I've had some success in creating low quality asset packages just for mobile safari.

Thanks.
To unsubscribe from this group and all its topics, send an email to emscripten-discuss+unsub...@googlegroups.com.

Александр Гурьянов

unread,
Nov 7, 2017, 11:59:19 PM11/7/17
to emscripte...@googlegroups.com
I can confirm that I also have same issue with some games on safari browser. Game runs slow until you minimize/maximize browser or attach debugger. I made a lot of profiling, but does not have success, profiler shows that overall performance changes after "magic" not single function. My theory is that safari can't find time to optimize js, I think it's Safari bug. I have one game that ported to js with cheerp and same game with emscripten, cheerp game run fast from beginning, emscripten game works slow until minimize/maximize browser. Unfortunately resulting js is very different I can't compare it. 

8 Ноя 2017 г. 9:34 AM пользователь "Rang" <angr...@gmail.com> написал:
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/Agj-M1C6YzY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Johannes Ahvenniemi

unread,
Nov 8, 2017, 3:16:30 AM11/8/17
to emscripte...@googlegroups.com
I haven't had any progress with this issue. But I'm also seeing this on iOS chrome (or did when I last tried). Could you please check if chrome is an issue also on your devices?

To unsubscribe from this group and all its topics, send an email to emscripten-discuss+unsub...@googlegroups.com.

Александр Гурьянов

unread,
Nov 8, 2017, 5:22:12 AM11/8/17
to emscripte...@googlegroups.com
Yes, I remember that this issue also occurs in iOS chrome. I can't
check now, because it's hard to get this game working again.
>>>> an email to emscripten-disc...@googlegroups.com.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "emscripten-discuss" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/emscripten-discuss/Agj-M1C6YzY/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> emscripten-disc...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to emscripten-disc...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "emscripten-discuss" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/emscripten-discuss/Agj-M1C6YzY/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> emscripten-disc...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to emscripten-disc...@googlegroups.com.

Rang

unread,
Nov 8, 2017, 5:25:18 AM11/8/17
to emscripten-discuss
Yes, the issue also occurs on iOS Chrome. Probably because it uses the same JavaScript engine as Safari. iOS devices are the only ones giving me performance issues.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/Agj-M1C6YzY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Alon Zakai

unread,
Nov 8, 2017, 2:11:26 PM11/8/17
to emscripten-discuss
Latest iOS has WebAssembly support, we should check if this problem exists there too (in most cases, just adding -s WASM=1 is enough to get a wasm version).

If the problem still exists with wasm, that could indicate the issue is graphics or GC, as opposed to JIT performance, so we might need to talk to different Safari people. (Also, I think they would suggest we ship wasm now since it's faster anyhow, so we should check that before filing any bugs.)

To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/Agj-M1C6YzY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/Agj-M1C6YzY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Rang

unread,
Nov 8, 2017, 10:05:22 PM11/8/17
to emscripten-discuss
This issue does not seem to occur with the wasm version of the app. With the latest iOS, I've tested a wasm version and initial performance is much better than the JavaScript version. I've just tested on mobile Safari and the performance of the app on android and iOS are much more comparable. I have not yet tested iOS Chrome.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/Agj-M1C6YzY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/Agj-M1C6YzY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages