thunderbiscuit / padawan-wallet

The bitcoin wallet trainer on Android.
https://padawanwallet.com/
Apache License 2.0
111 stars 49 forks source link

QR image generating taking too long #278

Closed yellowHatpro closed 1 year ago

yellowHatpro commented 1 year ago

https://user-images.githubusercontent.com/75999921/227734897-f0d64df6-f780-4a19-9c47-15ccb7dc674d.mp4

Fixes:

yellowHatpro commented 1 year ago

@thunderbiscuit is the issue there on other devices?? Can you confirm if it persists in your device/emulator?

thunderbiscuit commented 1 year ago

Yes I think there are a few things at play here. This is a good place to discuss maybe what's wrong with this screen.

One of the issues with that screen (I have not deeply investigated this yet) is that it tends to trigger a lot of recompositions of the composables. I'm not sure why.

In theory, the main thread at that point does nothing else than get this address from the wallet. I don't know that sending this work to a background thread should "speed it up" per se. I'm also not sure which part is actually the slowest part of this process. Is it the call to the Wallet object? Or the addressToQR() function? We could potentially pre-compute these things on a background thread as the user opens the screen and have it ready for them before they even click the button, which would then make it seem like the process was really fast. But even that feels a bit like over-optimization to me at the moment. Any thoughts on that?

On my devices and emulators it's not very slow to load this address (as opposed to navigating to the screen itself, which tends to be a bit slow I find).

yellowHatpro commented 1 year ago

I think generating the address is not a problem, but generating an image without thread switching will block the main thread. So what I am doing is, that I am calling the addressToQR() function within a LaunchedEffect, which depends on the address itself, so the image generation is now bound to the address, which I don't think changes frequently or on its own.

yellowHatpro commented 1 year ago

I will try to check if there are other recompositions in the mentioned screen, but I suppose generating the QR in the background should be a safe call. Although, it might be noticeable to me because my device is a slow potato >﹏<.

thunderbiscuit commented 1 year ago

Generating the image in the background is a good way to keep the UI from freezing, but I don't know how it can address your issue of the slowness of it directly.

yellowHatpro commented 1 year ago

Yeah slow won't be an appropriate word here. I was referring to the delay it causes.