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

Bring out the difference in usage of StringBuilder and StringBuffer #29

Closed
vadimklimov opened this issue Dec 13, 2023 · 5 comments
Closed
Assignees
Labels
contribution Valuable Contribution mission-award SAP Community mission award

Comments

@vadimklimov
Copy link
Contributor

Issue description

The documentation contains the following recommendations:

Don't use string objects for string literals that are frequently changed. This causes performance issues as several string objects are created in memory that are consecutively concatenated. This can cause problems when processing large payloads, <...>.

Instead, use the corresponding StringBuilder and StringBuffer classes, which help to avoid the creation of multiple intermediate string objects, <...>.

The usage of classes that offer mutability (such as StringBuilder and StringBuffer) instead of immutable String objects for string literals that are subject to frequent manipulations/changes makes great sense. Though while reading this recommendation, it may not be immediately obvious what use cases are for StringBuilder compared with StringBuffer, and these two may be considered to be interchangeable.

It may be worth highlighting the difference between StringBuilder and StringBuffer. While both are used to create mutable objects that can be further stringified, StringBuffer's public methods are synchronized, leading to thread safety of StringBuffer objects in a multi-threaded environment, whereas StringBuilder is not thread-safe. On the other hand, thread safety comes at the cost of performance overhead. As a result, it shall be evaluated and assessed if thread safety / synchronization is truly required - if so, StringBuffer shall be considered, and if thread safety is not a concern, performance can be further optimized by using StringBuilder instead.

While SAP Cloud Integration runtime is a multi-threaded environment, I can only come up with a handful of relevant use cases where synchronization is required for string representations that are manipulated in Groovy scripts, which makes me think that StringBuilder shall have a broader range of use cases than StringBuffer in scripts developed in SAP Cloud Integration.

Feedback Type (Optional)

clarity

Page Title on SAP Help Portal (prefilled)

General Scripting Guidelines

Page URL on SAP Help Portal (prefilled)

https://help.sap.com/docs/cloud-integration/sap-cloud-integration/general-scripting-guidelines

@MelanieCueppers
Copy link
Contributor

Thank you for your feedback! We’ll look into it and come back to you if we have any questions.

@MelanieCueppers MelanieCueppers added the ua-review Under review by the UA team. label Dec 14, 2023
@AnnikaGonnermann
Copy link

Dear @vadimklimov - thanks so much for your valueable feedback. We've made adjustments which will hopefully cover your use case. Please wait for the next publications of the documentation! Best Annika

@AnnikaGonnermann AnnikaGonnermann added contribution Valuable Contribution and removed ua-review Under review by the UA team. labels Dec 20, 2023
Copy link

sap-doc-bot bot commented Dec 20, 2023

Thank you for your valuable feedback contribution, @vadimklimov! So that we can recognize your contribution in SAP Community, please tell us your SAP Community profile URL in a reply to this comment; don't include any other text, just the URL on its own, like this:

https://people.sap.com/your-user-name

Thanks!

@vadimklimov
Copy link
Contributor Author

@vadimklimov
Copy link
Contributor Author

@AnnikaGonnermann, thank you for your time and efforts when assessing and evaluating this proposal, and for accepting it.

And a special thanks to you and the entire team for your openness and collaboration with the community on this initiative - this is very much appreciated.

@qmacro qmacro added the mission-award SAP Community mission award label Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution Valuable Contribution mission-award SAP Community mission award
Projects
None yet
Development

No branches or pull requests

5 participants