nbarkhina / N64Wasm

A web based N64 Emulator
https://www.neilb.net/n64wasm/
MIT License
624 stars 133 forks source link

Slower due to Ipad iOS 17.4 #43

Open BeezBumba opened 8 months ago

BeezBumba commented 8 months ago

When I updated my Ipad to 17.4 I went to my remixed emulator of yours and it started to lag much more than last time. I even tried yours, but it still resulted into a really laggy experience. I don’t know if it’s the update or if it’s something else.

BeezBumba commented 8 months ago

I was also on safari if that helps with anything.

nbarkhina commented 8 months ago

Were you able to fix this? I didn't test on 17.4 yet

BeezBumba commented 8 months ago

No, but it might need tweaking on the webkit feature flags for safari I believe. I’m not sure but it might be a way.

nbarkhina commented 8 months ago

Yeah I just tried it this morning on 17.4 on my iPhone 13 mini and can confirm it is really laggy now. Seems like Apple changed something in Safari. I will also play around with the feature flags and see if there is any workaround for this.

BeezBumba commented 8 months ago

I know they added WebGPU, WebRTC stuff, and 2 or more WebGL settings. It was not talked about in the update and it’s probably something directly on the webkit website. I might be wrong and it might be something else though.

BeezBumba commented 8 months ago

Did you find anything that may help yet?

nbarkhina commented 8 months ago

Nope nothing yet

BeezBumba commented 8 months ago

I have sent a website issue note to apple because now I'm not really sure what could be the issue. I am suspecting its memory only because when I was editing a Google Slides presentation, whenever I would copy and paste, it can take a while for it to paste.

nbarkhina commented 8 months ago

Great - let me know if they come back with anything. Yeah my guess is there's not much we can do unless Apple fixes the issue.

BeezBumba commented 8 months ago

I now know that it’s not something with the feature flags. I tried enabling/disabling all of them to see if there is a difference, but there was no difference.

BeezBumba commented 8 months ago

One more thing. My app store is not working for some reason, so can you try to see if the website works for other browsers?

nbarkhina commented 8 months ago

I tried in Chrome but it's the same result. All iOS browsers use the same engine.

BeezBumba commented 8 months ago

Quick question: Is there any part of your scripts that tries to sync the gameplay with the audio if the audio is acting slow? I saw a part in the script.js script that is highlighted and says that it’s outdated and use a different one.It suggested AudioWorkletNode instead of the deprecated ScriptProcessorNode.

BeezBumba commented 8 months ago

It also has benefits like working on a separate thread instead of the main thread.

nbarkhina commented 8 months ago

it only tries to sync to the audio if you uncheck this box - but that code isn't super reliable. I probably need to remove it anyway in a future update (it should always just use vertical sync for the timing). Yes over time if I can figure out web workers I want to try and offload the audio stuff to a separate thread.

image

BeezBumba commented 8 months ago

17.4.1 has just been released. Have you tried it yet to see if it fixed the issue?

BeezBumba commented 8 months ago

Also, I did find something intresting. On this website running Banjo-Kazooie, It ran much smoother than this one. Here is the website: https://selenite.is-a.dev/semag/banjokazooie/index.html. It seemed like the code did not get affected by the new update. Maybe there was something outdated that just made it slower?

nbarkhina commented 8 months ago

17.4.1 did not help - for me I've tried other emulators they all run slow for me. Seems to be a wider issue.

BeezBumba commented 8 months ago

What were the other emulators you’ve tried?

nbarkhina commented 8 months ago

the one you linked to. if you wait a minute after the intro screen it starts lagging

BeezBumba commented 8 months ago

For me, the save select screen in the game runs faster. Did you get there?

nbarkhina commented 8 months ago

point being I wouldn't call it "playable". perhaps some screens with less geometry run ok, but get to the outside and its very bad. this really needs to be fixed on Apple's side, I don't think any little optimizations here are sufficient.

BeezBumba commented 8 months ago

Did you find this blog: https://webkit.org/blog/15063/webkit-features-in-safari-17-4/ ? If it’s a problem that Apple has to fix. It might be helpful to find the issue anyways.

nbarkhina commented 8 months ago

nothing in the article really sticks out to me unfortunately

BeezBumba commented 8 months ago

I just found this website https://demo.emulatorjs.org/ that ran fullspeed for me. It uses Retroarch as the emulator. This might have to do with the Webkit engine, Since that actually runs and renders the web pages. They could of changed something up with the power some libraries use, most likely the deprecated ones.

nbarkhina commented 8 months ago

Runs just as slow for me for some reason. I tried Mario 64 and only the save select screen runs fast, everything else slow.

BeezBumba commented 8 months ago

That’s weird. my Ipad 8th generation is running smoothly on that website I gave you.

BeezBumba commented 7 months ago

Do you have any ideas still? Apple has not responded back yet and I'm completely oblivious of what could be the issue.

nbarkhina commented 7 months ago

Nope - does not seem to be much we can do unless Apple hopefully fixes this some day.

nbarkhina commented 7 months ago

@BeezBumba ok I may have a fix, stay tuned...

nbarkhina commented 7 months ago

ok I made some updates can you try this version and let me know how it runs for you?

https://neilb.net/n64wasm/vbo_test/

BeezBumba commented 7 months ago

It works! The only thing you have to do is request the mobile website by clicking the Aa on the left hand side on the address bar. But, thank you so much! What did you change? IMG_2423

nbarkhina commented 7 months ago

Take a look at my last commit - you can see the changes I had to make to fix it.

https://github.com/nbarkhina/N64Wasm/commit/aca7b9846cae3da1e1d46c5e63503c3ee983cf8f

For iOS devices I switched it to use something called "vertex buffer objects" which seems to resolve the rendering lag introduced in Safari.

BeezBumba commented 7 months ago

Awesome, I'm putting the changes in the codespace so it can generate the new js and wasm files right now.

BeezBumba commented 7 months ago

Can I also ask how you though of vertex buffer objects?

nbarkhina commented 7 months ago

I did some experimentation and isolated the slowness to the glDrawArrays call in geometry.c - that is where it draws all the triangles for the scene. So I was looking at ways to speed that up or make it more efficient. I remembered seeing the VBO code before but I wasn't sure what it did at the time so I commented it out. So I tried adding it back and to my surprise it worked. My understanding is that vertex buffer objects offer certain performance gains.

BeezBumba commented 2 weeks ago

What if i were to change the vertex buffer size. what would that do?

nbarkhina commented 2 weeks ago

Not sure - give it a shot and let me know

BeezBumba commented 2 weeks ago

So doubling it to 3000 did not impact the issue a lot so i saw the todo stuff on the top

/* TODO: get rid of glitch_vbo */
/* TODO: try glDrawElements */
/* TODO: investigate triangle degeneration to allow caching GL_TRIANGLE_STRIP */

What were you going to use these for?

nbarkhina commented 2 weeks ago

I can't even remember if those were my todos - it sounds like I may have been experimenting with performance

BeezBumba commented 2 weeks ago

yeah those were the original page's todos

BeezBumba commented 1 week ago

Was it just the glDrawArrays that you found that was slow?

nbarkhina commented 1 week ago

I'm not sure what aspect specifically was slow. My iPhone is on 18.1 - I just tried it and it runs fine for me.

BeezBumba commented 1 week ago

It just that most games run full speed except for these ones that I’ve tried: NFL QB CLUB 2000 & 2001, and some sm64 mods. There might be more, but I’m pretty sure all of them have the same issue. Summing it up some games are still laggy and I’m wondering if there was anything else other than the glDrawArrays.