Skip to content

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
@github-actions
Copy link
Contributor

github-actions bot commented Jan 14, 2025

Test Results

   494 files  ±0     494 suites  ±0   9m 42s ⏱️ -9s
 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 9143f85. ± Comparison against base commit d441a95.

♻️ 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
@jukzi jukzi merged commit d04d5a4 into eclipse-platform:master Jan 23, 2025
10 of 14 checks passed
HeikoKlare added a commit to vi-eclipse/eclipse.platform.swt that referenced this pull request Feb 26, 2025
This fixes wrong formatting introduced to the Win32 display class in
eclipse-platform#1722
HeikoKlare added a commit to vi-eclipse/eclipse.platform.swt that referenced this pull request Mar 5, 2025
This fixes wrong formatting introduced to the Win32 display class in
eclipse-platform#1722
HeikoKlare added a commit that referenced this pull request Mar 5, 2025
This fixes wrong formatting introduced to the Win32 display class in
#1722
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