Bug 155511 - GC.drawPolyline(...) very slow if line width > 0 - was: Squiggles and margin painter slow on long lines
Summary: GC.drawPolyline(...) very slow if line width > 0 - was: Squiggles and margin ...
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2006-08-29 04:47 EDT by Anton Leherbauer CLA
Modified: 2006-11-23 11:40 EST (History)
3 users (show)

See Also:


Attachments
Test project (1.18 KB, application/x-zip-compressed)
2006-08-29 07:38 EDT, Anton Leherbauer CLA
no flags Details
Thread dumps while busy drawing (13.07 KB, text/plain)
2006-08-29 07:42 EDT, Anton Leherbauer CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Anton Leherbauer CLA 2006-08-29 04:47:19 EDT
The squiggles drawing strategy together with enabled margin painter degrades drawing performance for long lines.

To reproduce:
- change drawing strategy of bookmarks to squiggles
- create a simple text file with a long line (~ 4000 characters)
- enable the print margin painter
- create a bookmark on the long line
- observe sluggish drawing (and very high CPU usage)

Interestingly, enabling the margin painter after creating the bookmark does not degrade performance.
Comment 2 Anton Leherbauer CLA 2006-08-29 07:38:20 EDT
Created attachment 48953 [details]
Test project

Steps to reproduce:
- import test project into a workspace using plain Eclipse SDK
- import preferences file "preferences.epf" contained in the project
- open file "longline.txt" with default Eclipse Text Editor
- create a bookmark on line 4
- type text into line 4
Comment 3 Anton Leherbauer CLA 2006-08-29 07:42:35 EDT
Created attachment 48955 [details]
Thread dumps while busy drawing
Comment 4 Anton Leherbauer CLA 2006-08-29 07:48:08 EDT
I did not test other platforms, but it definitely happens on 
- Windows XP SP 1
- Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode)
- Eclipse SDK 3.2 (Build id: M20060629-1905)
Comment 5 Dani Megert CLA 2006-08-29 12:36:11 EDT
Can reproduce now.

The problem is that normally the GC's line width is 0 which means "use fastest possible algorithm". The MarginPainter sets this to 1 since it wants to have 1 pixel width guaranteed. Using 1 seems to bring the performance of drawPolyline(...) down to the knees. If e.g. 5 is used it is even worse.

We now explicitly set the GC's line with to 0 when drawing the squiggles.

Moving to SWT to investigate the performance problem.
Comment 6 Steve Northover CLA 2006-08-29 15:28:38 EDT
If you want to draw the fastest possible line, you should use line width zero.  On X (and some other graphics systems), this tells the graphics subsystem to optimize the line drawing as much as possible, making use of any special drivers.  However, the output might not be identical to the same line drawn with line width one (but both lines will be one pixel wide).

Having said all that, we still might have a performance problem here.
Comment 7 Dani Megert CLA 2006-08-30 02:12:19 EDT
>If you want to draw the fastest possible line, you should use line width zero. 
Yep, that's what we now ensure to be used for the squiggles painter but the print margin painter has API to set the width.

>However, the output might not be identical to the same line drawn
>with line width one (but both lines will be one pixel wide).
So, they will both we 1 but how would they differ then? Does it mean that width 0 can override the line style then?
Comment 8 Steve Northover CLA 2006-08-30 10:09:19 EDT
No it means that on X for example, the actual pixels that are drawn may vary.  When the width is one, X uses "slow code" that follows a well know algorithm, making sure the pixels are the same between two different X platforms.  When the width is zero, X is free to use "optimized code" in the driver.

I'm a bit surprised that Windows does this sort of thing too and suspect our code.  That's why I didn't close this bug report.
Comment 9 Silenio Quarti CLA 2006-11-22 15:34:08 EST
There is nothing that SWT can do about this. If a PS_GEOMETRIC pen needs to be used, it will be alot slower than a PS_COSMETIC pen. PS_COSMETIC can be used with line widths other than 0, but the following properties have true as well:

cap=SWT.CAP_ROUND
join=SWT.JOIN_ROUND
dashes=null
style=SWT.LINE_SOLID
Comment 10 Dani Megert CLA 2006-11-23 02:24:09 EST
According to your explanation this is then either WONTFIX or INVALID since I just explained that you also see the degradation. WORKSFORME indicates that you could not reproduce what got reported.

Maybe a hint in Javadoc that even using 1 pixel instead of fastest can have this non-minor performance impact?
Comment 11 Silenio Quarti CLA 2006-11-23 11:40:31 EST
I guess I was trying to say WORKASEXPECTED. The note is already in the javadoc for setLineWidth().
Comment 12 Silenio Quarti CLA 2006-11-23 11:40:57 EST
closing again.