GCX-HCI / tray

a SharedPreferences replacement for Android with multiprocess support
Apache License 2.0
2.29k stars 273 forks source link

has lot of blocked operations reported from blockcanary #114

Closed eggcaker closed 7 years ago

eggcaker commented 7 years ago

I saw lot of blocked reported from blockcanary when i cannot any type prefs read (getInt getBoolean), i have around 100 try items saved in TrayPreferences table. it should be very faster to read

passsy commented 7 years ago

Because tray supports multi process it is quite slow. It's also not intended to read/write tray preferences on the main thread. If you want something fast use the SharedPreferences but you'll lose multi process support.

eggcaker commented 7 years ago

if I have lot of read/write operation at same time, should I change to async call ?

thelou1s commented 7 years ago

Yes, me too。 ANR traces reported:

"main" prio=5 tid=1 Native | group="main" sCount=1 dsCount=0 obj=0x753b8598 self=0xf4f36500 | sysTid=18059 nice=0 cgrp=default sched=0/0 handle=0xf76d6d54 | state=S schedstat=( 0 0 0 ) utm=21 stm=55 core=2 HZ=100 | stack=0xff6bd000-0xff6bf000 stackSize=8MB | held mutexes= native: pc 0000000000041228 /system/lib/libc.so (ioctl+8) native: pc 0000000000047ca5 /system/lib/libc.so (ioctl+14) native: pc 000000000001e96d /system/lib/libbinder.so (_ZN7android14IPCThreadState14talkWithDriverEb+132) native: pc 000000000001efdf /system/lib/libbinder.so (_ZN7android14IPCThreadState15waitForResponseEPNS_6ParcelEPi+38) native: pc 000000000001f195 /system/lib/libbinder.so (_ZN7android14IPCThreadState8transactEijRKNS_6ParcelEPS1_j+124) native: pc 000000000001a11b /system/lib/libbinder.so (_ZN7android8BpBinder8transactEjRKNS_6ParcelEPS1_j+30) native: pc 000000000008d635 /system/lib/libandroid_runtime.so (???) native: pc 0000000000f38429 /system/framework/arm/boot.oat (Java_android_os_BinderProxy_transactNativeILandroid_os_Parcel_2Landroid_os_Parcel_2I+140) at android.os.BinderProxy.transactNative (BinderProxy.java) at android.os.BinderProxy.transact (BinderProxy.java:503) at android.app.ActivityManagerProxy.refContentProvider (ActivityManagerProxy.java:4339) at android.app.ActivityThread.releaseProvider (ActivityThread.java:6641)

passsy commented 7 years ago

Handle Tray like a database. You wouldn't read/write data on the main thread. Move the code to some other Thread.

The API isn't async because most times you use Tray you have a mutliprocess case mostly without UI where you anyways shouldn't run blocking code on the main thread. (i.e. handle some FCM Notification in a Service, SyncAdapter, BroadcastReceiver, TileService, ...)

Short: Don't run Tray on the main thread, make it async when you use it in your Activities. All non UI stuff should be already off the main thread, use the synchronous API there.