Skip to content

Conversation

ejona86
Copy link
Member

@ejona86 ejona86 commented Oct 8, 2025

Just a sketch, but the neat thing is if we trigger the ServiceLoader optimization, that will keep the constructors for us, so we could use the hard-coded list or the fake-ServiceLoader-iterator and it should work fine either way.

}
return candidates.get(0);
final PriorityAccessor<T> priorityAccessor) {
return loadAll(klass, ServiceLoader.load(klass, cl).iterator(), hardcoded, priorityAccessor);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're concerned about the performance of clients not using R8, I think you'll want to make the call to ServiceLoader.load() conditional on R8 being used. Otherwise the hardcoded fallback will never be used. I'm not aware of a way to do that aside from adding an -assumevalues rule.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my reading of ServiceLoader, load() doesn't do any reflection. All the reflection is done when iterating. So while we may create the ServiceLoader here, we'll throw the ServiceLoader's iterator away without using it on Android if it isn't derived from a List. That's a bit of a hack, but also seems reasonably likely to remain stable. But -assumevalues might be a good option too (assuming we can set it without upsetting non-R8 shrinking tools).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! Does look that way on android at least.

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

Successfully merging this pull request may close these issues.

2 participants