Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed the public suffix database list directly inside a class #8589

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

yschimke
Copy link
Collaborator

@yschimke yschimke commented Nov 24, 2024

Attempt a fix for #8580

Removes the need for proguard for the database. At the cost of more costly code generation at build time.

Point at which we parse the file

java.lang.Exception
	at okhttp3.internal.publicsuffix.EmbeddedPublicSuffixList.<clinit>(EmbeddedPublicSuffixList.kt:35)
	at okhttp3.internal.publicsuffix.PublicSuffixDatabase.<clinit>(PublicSuffixDatabase.kt:157)
	at okhttp3.Cookie$Companion.parse$okhttp(Cookie.kt:561)
	at okhttp3.Cookie$Companion.parse(Cookie.kt:450)
	at okhttp3.CookiesTest.acceptOriginalServerMatchesSubdomain(CookiesTest.kt:306)

Generated source looks like, and both the source and class file are 57KB.

  override val bytes: ByteString = "Y2l0eS5rYXdhc2FraS5qcApjaXR5LmtpdGFreXVzaHUuanAKY2l0eS5rb2JlLmpwCmNpdHkubmFnb3lhLmpwCmNpdHkuc2FwcG9yby5qcApjaXR5LnNlbmRhaS5qcApjaXR5Lnlva29oYW1hLmpwCnd3dy5jawo=".decodeBase64()!!

okhttp/build.gradle.kts Outdated Show resolved Hide resolved
filteringCharset = Charsets.UTF_8.toString()

// TODO replace with KotlinPoet?
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggestions welcome!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since KotlinPoet generates source, this doesn't seem like a big win.

@yschimke yschimke marked this pull request as ready for review November 24, 2024 11:31
@yschimke
Copy link
Collaborator Author

@yschimke
Copy link
Collaborator Author

I shouldn't have uncompressed it. Will compare the compressed version

Copy link
Collaborator

@JakeWharton JakeWharton left a comment

Choose a reason for hiding this comment

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

I'll review the rest on desktop. Too dense for mobile.

@@ -9,12 +13,27 @@ plugins {
id("binary-compatibility-validator")
}

// Build & use okhttp3/internal/-InternalVersion.kt
fun ByteArray.toByteStringExpression(): String {
return "\"${Base64.getEncoder().encodeToString(this@toByteStringExpression)}\".decodeBase64()!!"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like byteArrayOf would save even more space since it would be stored raw instead of as a string that is then encoded to bytes for the classfile.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, I'll try that. I was hitting limits of Kotlin? compiler before, with the source file like "...12, 15, -34, -56, 12..."

But let me try again

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Source back to 150KB, Kotlin compiler is noticeably struggling with the build. When the compile completes I'll report on the class file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've given up on that for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably worth filing a Kotlin issue if it's not fast. Although this project is stuck on old Kotlin with the old compiler, I believe.

Could also just generate package-private Java with a single static field.

@yschimke
Copy link
Collaborator Author

One alternative is to leave the existing implementation in src/main as the default, until we get a version that we are happy with and then switch.

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