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

[FIX] Change to old withCrLf for better performance #1722

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Christopher-Hermann
Copy link
Contributor

Changing back to the old withCrLf coding. Regex is causing performance issues.

Furthermore, handling of mixed \n and \r\n is improved.

Fixes: #1718

@Christopher-Hermann Christopher-Hermann self-assigned this Jan 14, 2025
Copy link
Contributor

github-actions bot commented Jan 14, 2025

Test Results

   494 files  ±0     494 suites  ±0   10m 15s ⏱️ + 1m 34s
 4 326 tests ±0   4 308 ✅ ±0   18 💤 ±0  0 ❌ ±0 
16 536 runs  ±0  16 388 ✅ ±0  148 💤 ±0  0 ❌ ±0 

Results for commit a0af9a4. ± Comparison against base commit 22eece1.

♻️ This comment has been updated with latest results.

@jukzi
Copy link
Contributor

jukzi commented Jan 14, 2025

reduces time from 9 to 4 sec :-)

if (length == 0) return string;

/*
* Check for an LF or CR/LF and assume the rest of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check could also be left away. Especially since it does not work with partly mixed delimiters and does not improve performance either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about that one. If there is a really long text with correct line breaks (\r\n) this will save some time. For example withCrLf("\r\n".repeat(100_000_000));.

On the other hand, as you said, this is not working with partly mixed delimiters. So I'm not really sure how to proceed here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about that one. If there is a really long text with correct line breaks (\r\n) this will save some time.

did you measure it? Anyhow Functional correctness beats performance requirements

Copy link
Contributor Author

@Christopher-Hermann Christopher-Hermann Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using withCrLf("\r\n".repeat(100_000_000)); results in a noticeable performance difference: the operation takes 13ms with the check and 1382ms without it. Given that most strings passed to Display.withCrLf are likely already correctly formatted with proper line breaks, this optimization could significantly impair the overall performance of Eclipse.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

13ms with the check and 1382ms without it.

that sounds like a big difference, but its only that fast because the check stops at the first occurrence. the following handling of the String however will still need to walk through the entire string so that in the broader context it may not be a hotspot but negligible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly. This only saves time for already correctly formatted strings. I removed the check, it's still better than the regex/replaceAll version.

I would suggest to merge it without the check and if we see that it impairs the performance we can change it.

@Christopher-Hermann
Copy link
Contributor Author

Test seems to be unrelated, but I'm not sure...

Changing back to the old withCrLf coding. Regex is causing performance issues.

Furthermore, handling of mixed \n and \r\n is improved.

Fixes: eclipse-platform#1718
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.

Slow org.eclipse.swt.widgets.Display.withCrLf(String)
2 participants