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

Micro optimisation: calls to String.replaceAll need to be replaced #1608

Closed
2 tasks done
01es opened this issue Oct 22, 2020 · 0 comments · Fixed by #1613
Closed
2 tasks done

Micro optimisation: calls to String.replaceAll need to be replaced #1608

01es opened this issue Oct 22, 2020 · 0 comments · Fixed by #1613
Assignees
Milestone

Comments

@01es
Copy link
Member

01es commented Oct 22, 2020

Description

String.replaceAll is implemented using regular expression with a pattern compiled upon each call. Matching even short strings is computationally expensive. In TG we have multiple places where String.replaceAll is used extensively and some places where it is used accidentally, and String.replace would suffice.

Performance of String.replace is much better as it does not support regular expression. However, under Java8 it still performs worse than alternative StringUtils.replace() from Apache Commons Lang, which has optimisation for strings with no matches. Starting with Java9, the performance for String.replace is equivalent to StringUtils.replace().

Therefore, the main objective of this issue is to inspect all calls to String.replaceAll and improve them.

  • Replace calls to String.replaceAll to String.replace where no regular expression matching is necessary, and with StringUtils.remove where replacement is with an empty string.

  • Replace calls to String.replaceAll where regular expression is needed by using a precompiled pattern where possible. RegExUtils could be conveniently used for this purpose.

- [ ] Consider replacing String.split with Guava Splitter for optimal performance. -- String.split turned out to be more efficient.

Expected outcome

Improved performance.

@01es 01es self-assigned this Oct 22, 2020
@01es 01es added this to the v1.4.5 M9.1 milestone Oct 22, 2020
01es added a commit that referenced this issue Oct 26, 2020
01es added a commit that referenced this issue Oct 27, 2020
…cement with empty string, using various ways.
01es added a commit that referenced this issue Oct 27, 2020
…chmark methods -- benchmark classes (even patterns) can be specified as command line arguments.
01es added a commit that referenced this issue Oct 27, 2020
01es added a commit that referenced this issue Oct 27, 2020
01es added a commit that referenced this issue Oct 27, 2020
01es added a commit that referenced this issue Oct 27, 2020
01es added a commit that referenced this issue Oct 27, 2020
@01es 01es mentioned this issue Oct 28, 2020
01es added a commit that referenced this issue Oct 28, 2020
01es added a commit that referenced this issue Oct 28, 2020
jhou-pro added a commit that referenced this issue Oct 28, 2020
oleh-maikovych pushed a commit that referenced this issue Nov 2, 2020
oleh-maikovych pushed a commit that referenced this issue Nov 2, 2020
…cement with empty string, using various ways.
oleh-maikovych pushed a commit that referenced this issue Nov 2, 2020
…chmark methods -- benchmark classes (even patterns) can be specified as command line arguments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants