okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

Allow customization of public suffix DB loading behavior by Platform

Open Esteth opened this issue 1 year ago • 3 comments

On some platforms, Java Resources are expensive to load and encode compared to a platform's native solution for bundling data. The public suffix file is loaded using Java Resources.

This is the case on Android, where Android Resources are faster to load and smaller to store than Java Resources as used in PublicSuffixDatabase.kt

Ideally, each Platform could choose to override the loading behavior for the public suffix database, falling back to the default behavior with java resources since it's supported on all java platforms.

Esteth avatar Nov 18 '24 20:11 Esteth

We have an android module, so we could make it conditional on that. I'll take a look.

But we would need to prove it's noticeably faster to be worth the effort.

yschimke avatar Nov 18 '24 21:11 yschimke

I'm virtually certain there are memory wins to be had because AFAIK using Java Resources on android require holding the EOCD zip table for the whole APK in memory in perpetuity once they've been accesed. Loading that table from disk and unpacking it can also take some time.

For small apps this is a small cost, but for large apps that table can be large (1MB+) because it contains strings for all the files in the APK among other things.

Esteth avatar Nov 18 '24 23:11 Esteth

It's only 40KiB. It could fit into a ByteArray of some class...

JakeWharton avatar Nov 19 '24 01:11 JakeWharton

released in 5.0

yschimke avatar Jul 26 '25 13:07 yschimke