Skip to content

Conversation

uli-f
Copy link
Member

@uli-f uli-f commented Dec 13, 2024

As this changes an interface it is technically a breaking change.

I also replaced StringBuilder with a String concatenation as recommended for fixed number of string concatenations.

…r with String concatenation as recommended for fixed number of string concatenations
@egonw
Copy link
Member

egonw commented Dec 13, 2024

I would leave out the StringBuilder change. That was put in for performance, and indeed may well be outdated, with so much compiler work since. But before doing this, let's see if it doesn't make things slower, to be sure. If not, we can apply this at a lot more places in the core classes. So, imo, better as a separate patch/PR.

But happy with the API extension. We do need tests for the new functionality.

@uli-f
Copy link
Member Author

uli-f commented Dec 13, 2024

Thanks Egon for your feedback.

I was big on putting StringBuilder everywhere, until I read this recently. In summary: with Java 8 the compiler transforms the concatenation into StringBuilder calls, so nothing gained, nothing lost. With Java >8, StringBuilder is actually not even recommended as the string concatenation allows the JVM to choose the best implementation at runtime (JEP 280).

Basically, less typing, less convoluted code, better result 😃

Have a look and let me know what you think.

@uli-f
Copy link
Member Author

uli-f commented Dec 13, 2024

I'll put in the tests you asked for.

@egonw
Copy link
Member

egonw commented Dec 13, 2024

I was big on putting StringBuilder everywhere, until I read this recently. In summary: with Java 8 the compiler transforms the concatenation into StringBuilder calls, so nothing gained, nothing lost. With Java >8, StringBuilder is actually not even recommended as the string concatenation allows the JVM to choose the best implementation at runtime (JEP 280).

Great! Let's make this a todo.

@uli-f
Copy link
Member Author

uli-f commented Dec 13, 2024

Great! Let's make this a todo.

And just to clarify: This compiler / jvm optimization obviously only works if it can be inferred at compile time. For example, if a string concatenation happens in any loop, StringBuilder must still be used to not loose any performance.

@uli-f
Copy link
Member Author

uli-f commented Dec 13, 2024

Added tests.

@egonw I haven't removed the StringBuilder replacement, but I am happy to if you still prefer it to be removed. Just let me know.

@egonw
Copy link
Member

egonw commented Dec 13, 2024

but I am happy to if you still prefer it to be removed. Just let me know.

Nah, that can stay in.

@johnmay
Copy link
Member

johnmay commented Dec 13, 2024

All looks good to me, not a breaking change since it is adding and not changing the API.

@egonw egonw merged commit 0637ee5 into cdk:main Dec 14, 2024
6 of 7 checks passed
@uli-f uli-f mentioned this pull request Dec 16, 2024
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.

3 participants