Bug 195575 - StyledText.getLocationAtOffset is slow for long lines was: Long lines take too long to display when "Show Whitespace Characters" is enabled.
Summary: StyledText.getLocationAtOffset is slow for long lines was: Long lines take to...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.4 M2   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2007-07-05 14:56 EDT by Mark A. Ziesemer CLA
Modified: 2008-12-08 16:40 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark A. Ziesemer CLA 2007-07-05 14:56:46 EDT
Build ID: I20070625-1500

Steps To Reproduce:
1. Enable the "Show Whitespace Characters" feature.
2. Open a file containing a long line of data (>100 kB works well) in a text-based editor (text editor, or XML editor in Source mode).
3. Observe that Eclipse becomes unresponsive for 30+ seconds with 100% CPU utilization in Eclipse.exe.

Turning off the "Show Whitespace Characters" feature reduces this to about < 3 seconds.

More information:
Test machine is 2 GHz with 2 GB RAM, running Win2k.
Comment 1 Mark A. Ziesemer CLA 2007-07-05 17:39:16 EDT
I forgot to clarify - the issue here is long line lengths, not large files overall.  I commonly experience this on "unformatted" file types, such as non-formatted XML (the entire file is on one line), or other data types absent of line breaks.  I've not looked into the source code yet, but one guess is an operation that's trying to buffer "per line" rather than per a given block of characters.
Comment 2 Dani Megert CLA 2007-07-10 10:36:43 EDT
The main reason is the slow performance of computing the location for a given offset (see attached screenshot from the profiler).

Adding Anton who provided the initial implementation of the WhitespaceCharacterPainter. Anton, the WhitespaceCharacterPainter could be improved by not looping from start to end offset but instead do it line by line so that we can cut off at left and right of the viewport. Left and right need to be computed à la binary seach to minimize the calls to getLocationAtOffset(...). Could you look into that? If so we can clone that bug.

Moving to SWT to check whether they can improve the performance.
Comment 3 Anton Leherbauer CLA 2007-07-11 03:59:06 EDT
(In reply to comment #2)
> Could you look into that? If so we can clone that bug.

I can look into it for 3.4.
Comment 4 Dani Megert CLA 2007-07-11 04:07:17 EDT
Thanks Anton. I've created bug 196116 for that.
Comment 5 Felipe Heidrich CLA 2007-09-07 16:48:01 EDT
fixed in HEAD > 20070907

I changed TextLayout#getLocation and TextLayout#getOffset to use a binary search to find the run (used be linear search).
Comment 6 Steve Northover CLA 2008-12-08 16:32:27 EST
Felipe please verify that this fix is already in 3.4.x.
Comment 7 Felipe Heidrich CLA 2008-12-08 16:40:09 EST
(In reply to comment #6)
> Felipe please verify that this fix is already in 3.4.x.

It is there already.