mutiny-web icon indicating copy to clipboard operation
mutiny-web copied to clipboard

shared worker

Open futurepaul opened this issue 1 year ago • 7 comments

closes #601 (kind of)

I've confused the concept of ServiceWorker and SharedWorker a lot of times. What we have here is a SharedWorker... in the future this will make it easier for a ServiceWorker to connect to the one canonical instance of Mutiny, whether or not the app is open.

For now, the main win is getting all the mutiny work off the main UI thread. Everything should be more responsive (no blocking) and in some cases faster (no contention, so faster, though there is a serialization cost going across threads).

TODO:

  • [ ] add the doc strings
  • [ ] test everything

futurepaul avatar Apr 23 '24 20:04 futurepaul

Deploying mutiny-web with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8f94770
Status: ✅  Deploy successful!
Preview URL: https://6597b4b5.mutiny-web.pages.dev
Branch Preview URL: https://sw.mutiny-web.pages.dev

View logs

in some places you do sw.function() and others you do sw?.function() what is the reasoning there?

edit: I think I only actually saw one

benthecarman avatar Apr 23 '24 21:04 benthecarman

What we have here is a SharedWorker.

this site says it doesn't work for chrome android :cry:, will need to test

probably should add to the screen where we detect if js/wasm is enabled, that shared workers are available

benthecarman avatar Apr 23 '24 21:04 benthecarman

What we have here is a SharedWorker.

this site says it doesn't work for chrome android 😢, will need to test

probably should add to the screen where we detect if js/wasm is enabled, that shared workers are available

THIS IS SO SAD :(. It's a one line change to make it a non-shared worker, but I might look into detecting Chrome Android specifically so we can use sharedworker other places. But that means I need to bring back all the double init defense stuff :(

I'm also having trouble with capacitor right now. It's not working iOS or Android, for what might be different reasons. One problem is this import.meta.url which doesn't seem to exist in the Capacitor environment, trying to figure it out.

futurepaul avatar Apr 24 '24 16:04 futurepaul

Got android working...

Screenshot 2024-04-24 at 11 35 12 AM

But iOS is mad about something. Works in desktop safari...

Screenshot 2024-04-24 at 11 37 07 AM

futurepaul avatar Apr 24 '24 16:04 futurepaul

Everywhere where you do // PAIN in the worker is where we return a wasm_bindgen type instead of a JsValue this was supposed to be nicer for you but seems like it is worse now. Maybe in mutiny-wasm we should just try to do JsValue everywhere now

yeah it sucks because the JsValue erases the type so I have to go digging to figure out what it's actually returning. do you remember why this was rejected btw? https://github.com/MutinyWallet/mutiny-node/pull/882

futurepaul avatar Apr 25 '24 17:04 futurepaul

Wasm bindgen does the same thing, it just doesn't work for async functions yet. I think they recently merged support for it though

benthecarman avatar Apr 25 '24 18:04 benthecarman

My mainnet tests on my android phone are great. No more flicker. Page switches are much faster now. Signet will need a full end to end test but this is really smooth. Nice work!

AnthonyRonning avatar May 02 '24 20:05 AnthonyRonning

Screenshot 2024-05-02 at 4 34 57 PM

I don't think it's intended to be at the bottom?

AnthonyRonning avatar May 02 '24 21:05 AnthonyRonning