FastServiceLoader performs I/O on calling thread and prevents R8 optimization
See original GitHub issueThe fix to #878 that introduces a FastServiceLoader to mitigate the fact that ServiceLoader implementation on Android is slow is still inadequate for Android apps and moreover, the solution prevents the R8 optimization from working.
For Android apps to avoid doing I/O on the main thread, we should
- let the user disable the FastServiceLoader (this can be done now via setting a systemProp now, but is quite hidden and requires action from the developer)
- Enable the R8 optimization by making sure that any calls to ServiceLoader.load are of the form:
ServiceLoader.load(MyClass::class.java, MyClass::class.java.classLoader).iterator()
Everything matters here: 2 argument constructor, class constants as arguments, and the only call to the returned ServiceLoader has to be.iterator()
.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:6 (3 by maintainers)
Top Results From Across the Web
colintheshots | Colin The Shots
In this code, there was a repeated block at the end of every repository call to handle network, DNS, and timeout errors.
Read more >Scaling Up IO Tasks in Java - Medium
Here we use Thread.sleep()to simulate a long-running IO call. This is a blocking call and the thread is stuck for the given time...
Read more >Kotlin愛好会 vol.14でDispatchers.Mainについて談義してき ...
FastServiceLoader performs I/O on calling thread and prevents R8 optimization · Issue #1231 · Kotlin/kotlinx.coroutines · GitHub.
Read more >log: wangdaye.com.geometricweather:30100 - F-Droid Monitor
Get:1 http://deb.debian.org/debian stretch/main amd64 ... ProGuard optimize steps (and performs some # of these optimizations on its own).
Read more >Java源代码 - 摸瓜
C$r8$backportedMethods$utility$Long$1$hashCode.java ... KProperty0Impl$_getter$1.java; KClassImpl$Data$constructors$2.java; calls.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can also add
to do this at compile-time with R8 instead of at runtime with a property. Your APK also gets a teeeeeeny bit smaller!
Thanks, I can confirm that latest R8 master seems to produce a proper bytecode.
Unfortunately I’m not ready for R8 1.6 yet and will do my usual bug reports with Jinseong if any when AS 3.6 reach beta. After dozen of issues reported for 1.4/1.5 I’m playing safe now 😃
It may worth to add a note somewhere about the fact that it won’t work with 1.5 as without checking bytecode they could think it works.