-
Notifications
You must be signed in to change notification settings - Fork 14
perf: improve strings handling #636
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
Conversation
Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
pbj-integration-tests/src/jmh/java/com/hedera/pbj/integration/jmh/utf8/Utf8ToolsV2.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
|
For concern(1) I have one idea but don't love it. You could make the On concern (2) we should get a performance run with this branch by Alex to see how it effects CN performance before merging. If the gain is tiny or non-existent then lets not merge. |
|
Closing the PR per #620 (comment) . |
Description:
This is the last part of changes extracted from @jasperpotts 's draft PoC #612 . We store string fields as UTF-8 byte arrays internally in models. We allow codecs to parse original UTF-8 and implant them directly into the model w/o performing the UTF-8 decoding (which internally would convert the text into UTF-16 (or Latin-1) because that's how Java stores strings.) The public API of the models is unchanged, and whenever anyone calls a getter for a string field, the model will encode it into a Java string on the fly.
The idea behind this optimization is that we rarely read or use strings in our business logic. So we could as well skip the decoding part when parsing models.
Three caveats come with the fix:
byte[]for strings and also have a fake unused argument so as to resolve a generic erasure clash. This looks a bit ugly. Also, this is not very safe because it allows a malicious code to create a mutable model instance (by retaining references to theirbyte[]) and then pass the object to a code that expects the models to be immutable. We could make the constructorsprivate, but we'd have to move all the codecs into the same package with their models, which could be a breaking change.Related issue(s):
Fixes #620
Notes for reviewer:
All tests should pass.
Checklist