square / okhttp

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.
https://square.github.io/okhttp/
Apache License 2.0
45.88k stars 9.16k forks source link

Allow customization of public suffix DB loading behavior by Platform #8580

Open Esteth opened 3 hours ago

Esteth commented 3 hours ago

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.

yschimke commented 2 hours ago

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.

Esteth commented 8 minutes ago

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.