Fix detectCharset ANR#12
Conversation
|
Thanks for this. I haven't seen detectCharset take a significant amount of time (only the first few bytes are inspected in many cases), but I imagine there are inputs that take longer than others. Do you have an idea what kinds of inputs you have that are taking so long? Also, I am aware that there is a preference for coroutines over threads in Kotlin. Is there a reason you chose threads instead of coroutines? |
|
Hi, I saw these ANR's only in the crash logs, I don't have the input which triggered them. Locally is fast also for me. |
|
Sorry for the delay on this. Here's what's going on: My intuition is that detecting the charset itself is quite fast, so I wanted to reproduce this issue for myself to see exactly where the bottlenecks are. I did the following:
With a large payload, I see the UI is blocked for about 1.2s on my device, Then I thought, "why not eliminate the MethodChannel entirely by reimplementing this plugin as a direct FFI interface for uchardet"? So I'm partway through figuring out how to do that. But then I realized that we still need the decoding part, which is not covered by uchardet, and would still require a MethodChannel to use the platform's decoding features (unless there's a way to use that via FFI as well). I recognize that the Android implementation is entirely different (juniversalchardet in Java), so I will see if your change makes a material difference on my Android device. |
|
Can you check #13 to see if it addresses your issue? Or at least looks like it should? |
|
Thank you, it looks good to me. |
|
Equivalent changes are now released in flutter_charset_detector_android v3.1.0 |
There are a couple of ANR's in Google Play Console:
This change fixes the ANR caused by blocking the UI thread.