Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANR due to no caching #5

Open
sheinin opened this issue Dec 31, 2024 · 2 comments
Open

ANR due to no caching #5

sheinin opened this issue Dec 31, 2024 · 2 comments

Comments

@sheinin
Copy link

sheinin commented Dec 31, 2024

PlayStore console reports a frequent ANR

  #00  pc 0x0000000000595f34  /apex/com.android.art/lib64/libart.so (art::DumpNativeStack+108)
  #01  pc 0x00000000005985ec  /apex/com.android.art/lib64/libart.so (art::Thread::DumpStack const+376)
  #02  pc 0x000000000059a3e0  /apex/com.android.art/lib64/libart.so (art::DumpCheckpoint::Run+216)
  #03  pc 0x000000000022c234  /apex/com.android.art/lib64/libart.so (art::Thread::RunCheckpointFunction+144)
  #04  pc 0x0000000000990ae4  /apex/com.android.art/lib64/libart.so (artTestSuspendFromCode+152)
  #05  pc 0x000000000038379c  /apex/com.android.art/lib64/libart.so (art_quick_test_suspend+156)
  #06  pc 0x0000000003205390  /memfd:jit-zygote-cache (art_jni_trampoline+224)
  #07  pc 0x000000000230aad8  /memfd:jit-zygote-cache (java.util.regex.Pattern.fastSplit+680)
  at java.lang.String.fastSubstring (Native method)
  at java.lang.String.substring (String.java:2538)
  at java.util.regex.Pattern.fastSplit (Pattern.java:1251)
  at java.lang.String.split (String.java:3012)
  at java.lang.String.split (String.java:3064)
  at io.github.coordinates2country.Coordinates2Country.countryFromGrayshade (Coordinates2Country.java:161)
  at io.github.coordinates2country.Coordinates2Country.countryFromPixel (Coordinates2Country.java:147)
  at io.github.coordinates2country.Coordinates2Country.countryAtDistance (Coordinates2Country.java:103)
  at io.github.coordinates2country.Coordinates2Country.nearestCountry (Coordinates2Country.java:80)
  at io.github.coordinates2country.Coordinates2Country.country (Coordinates2Country.java:66)
  at io.github.coordinates2country.Coordinates2Country.country (Coordinates2Country.java:27)

or

  #00  pc 0x00000000000869cc  /apex/com.android.runtime/lib64/bionic/libc.so (syscall+28)
  #01  pc 0x000000000022a220  /apex/com.android.art/lib64/libart.so (art::ConditionVariable::WaitHoldingLocks+136)
  #02  pc 0x0000000000743ca8  /apex/com.android.art/lib64/libart.so (art::JNI<false>::CallIntMethodV+996)
  #03  pc 0x0000000000410f18  /system/lib64/libhwui.so (_JNIEnv::CallIntMethod+120)
  #04  pc 0x0000000000411300  /system/lib64/libhwui.so (JavaInputStreamAdaptor::read+128)
  #05  pc 0x000000000059bad4  /system/lib64/libhwui.so ((anonymous namespace)::FrontBufferedStream::read +260)
  #06  pc 0x0000000000345bb4  /system/lib64/libhwui.so (SkPngCodec::processData+276)
  #07  pc 0x00000000003459a0  /system/lib64/libhwui.so (SkPngNormalDecoder::decodeAllRows+96)
  #08  pc 0x00000000003209d4  /system/lib64/libhwui.so (SkCodec::getPixels+260)
  #09  pc 0x000000000054525c  /system/lib64/libhwui.so (SkSampledCodec::onGetAndroidPixels+92)
  #10  pc 0x000000000031f374  /system/lib64/libhwui.so (SkAndroidCodec::getAndroidPixels+260)
  #11  pc 0x000000000031d8b4  /system/lib64/libhwui.so (doDecode +1780)
  #12  pc 0x0000000000508e40  /system/lib64/libhwui.so (nativeDecodeStream +144)
  at android.graphics.BitmapFactory.nativeDecodeStream (Native method)
  at android.graphics.BitmapFactory.decodeStreamInternal (BitmapFactory.java:806)
  at android.graphics.BitmapFactory.decodeStream (BitmapFactory.java:781)
  at android.graphics.BitmapFactory.decodeStream (BitmapFactory.java:822)
  at io.github.coordinates2country.Coordinates2Country.country (Coordinates2Country.java:64)
  at io.github.coordinates2country.Coordinates2Country.country (Coordinates2Country.java:27)

It's very likely because of no caching, as stated here in the source code:

// Load it within this method and do not cache it, in order to allow garbage collection between each call, because we consider that low memory usage is more important than speed.
        InputStream inputStream = io.github.coordinates2country.Coordinates2Country.class.getResourceAsStream("/countries-8bitgray.png");

        ...

// Load it within this method and do not cache it, in order to allow garbage collection between each call, because we consider that low memory usage is more important than speed. This method is called only once per country(...) call.
            BufferedReader br = new BufferedReader(new InputStreamReader(io.github.coordinates2country.Coordinates2Country.class.getResourceAsStream("/countries.csv")));

Would it be possible to release an update with the caching option? thanks.

@nicolas-raoul
Copy link
Contributor

Thanks for reporting!

An option sounds reasonable indeed.

Would you be able to send a pull request?

Thank you! 🙂

@sheinin
Copy link
Author

sheinin commented Jan 14, 2025

Sorry for late response. It's a good idea, unfortunately needed more testing than anticipated. I moved calls to the lib from main thread and no ANR has been reported so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants