Skip to content

FastServiceLoader performs I/O on calling thread and prevents R8 optimization #1231

@wojtek-kalicinski

Description

@wojtek-kalicinski

The 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

  1. 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)
  2. 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().

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions