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

Performance issue in StringUtils #361

Open
jkronegg opened this issue Jan 31, 2025 · 2 comments
Open

Performance issue in StringUtils #361

jkronegg opened this issue Jan 31, 2025 · 2 comments
Assignees
Labels
πŸ› bug Defect / Bug

Comments

@jkronegg
Copy link
Contributor

πŸ‘“ What did you see?

In the Parser.parse() method, 30% to 50% of the elapse time is passed doing String trimming in the StringUtils class, see #351 (comment)

βœ… What did you expect to see?

No doubt String trimming is important, but it should not last that long.

πŸ“¦ Which tool/library version are you using?

OpenJDK21
gherkin 31.0.0 (the main branch)

πŸ”¬ How could we reproduce it?

See JMH benchmark code in #351 (comment)

πŸ“š Any additional context?

Identified for #351

@jkronegg jkronegg added the πŸ› bug Defect / Bug label Jan 31, 2025
@jkronegg jkronegg self-assigned this Jan 31, 2025
@mpkorstanje
Copy link
Contributor

Using a regular expression for trim looks very inefficiΓ«nt. It will be applied for every character in line.

It might be faster to find the last consecutive whitespace character from the start and end, and then take a substring.

@jkronegg
Copy link
Contributor Author

jkronegg commented Feb 2, 2025

The left trim, right trim and left+right trim operations are used for indentation purposes. Thus, rather than dumbly improving StringUtils, I'm thinking on a specific method which trims and idents at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
πŸ› bug Defect / Bug
Projects
None yet
Development

No branches or pull requests

2 participants