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

Discourage + string concatenation from FileDescriptors #239

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

seanreid-toast
Copy link

Why?

Due to a bug in the Kotlin Compiler, there's a high chance of stack overflow with protos medium+ sized protos (example tested: 1 service, ~20 RPCs, ~45 messages). When concatenating using the + operator in Kotlin, the complier can throw a stack overflow exception when generating the bytecode.

What changed?

This change is simple: it just makes the file descriptors into one long string rather than generating a broken string with + concatenation operators. This allows for larger protos before hitting a stack overflow exception.

Testing

All existing tests pass, including tests that validate descriptors match between ProtoKt and protobuf-java. Manual testing was conducted locally to verify that the proto that originally exposed this issue still caused a stack overflow on a branch without this change, but does not with this change

What about a test to capture a large proto?

One is written here. It has a new proto with a single message that has 319 string fields. 319 is one more than the maximum that works on my machine (macos 14.3, intel, amazon corretto 11.0.9.11.1) without causing another stack overflow in the compiler.

The number of fields needed to produce a string long enough to cause automatic rollover into a second line that requires concatenation is ~900-1000. So the point at which line wrapping is significantly larger than what seems to currently overflow the compiler stack. The branch linked above can be used to demonstrate this behavior.

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.

1 participant