-
Notifications
You must be signed in to change notification settings - Fork 45
Simplify conjure object toString implementation #555
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
Avoid using unnecessary stringbuilders, in jdk8 javac generates this code for us. Using a compiler target beyond jdk8 we can take advantage of [jep 280](https://openjdk.java.net/jeps/280).
Generate changelog in
|
conjure-java-core/src/main/java/com/palantir/conjure/java/types/MethodSpecs.java
Outdated
Show resolved
Hide resolved
|
since the described JEP is to translate the bytecode generation to the thing we were producing anyway, is this change actually that beneficial? |
|
Before jep280 java generated bytecode matching what we generated. Newer versions implementing jep280 generate simpler bytecode which can be optimized beyond stringbuilder. I can post example bytecode when I’m near a keyboard (likely won’t make it today) |
|
Using IntegerExample for simplicity. MethodologyClean and rebuild with an updated target version, and read bytecode using: Before this change (develop)With this change, targeting java 8Here we see the old (pre jep280) compiler optimization resulting in the code we used to generate. Note this is a bit more compact than the old implementation due to this PR combining delimiter and field name strings. With this change, targeting java 11This is much simpler, we're giving the runtime a great deal more freedom to presize the resulting string rather than being prescriptive about the implementation details. |
|
Thanks. Should there be a corresponding errorprone and refaster rule? |
That's a good idea. Filed palantir/gradle-baseline#831 |
|
Released 4.4.0 |
|
@markelliot automated fix is here, if you're interested: palantir/gradle-baseline#832 |
Avoid using unnecessary stringbuilders, in jdk8 javac generates
this code for us. Using a compiler target beyond jdk8 we can
take advantage of jep 280.
After this PR
==COMMIT_MSG==
Simplify conjure object toString implementation
==COMMIT_MSG==