Discourage +
string concatenation from FileDescriptors
#239
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.