Bug 90497 - [api][performance] Text framework creates tons of StyleRange objects
Summary: [api][performance] Text framework creates tons of StyleRange objects
Status: RESOLVED DUPLICATE of bug 2537
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
: 96462 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-04-06 13:48 EDT by Billy Biggs CLA
Modified: 2007-11-27 10:56 EST (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Billy Biggs CLA 2005-04-06 13:48:01 EDT
Bug 90179 raises a memory issue which is due to the large number of StyleRange
objects created by Eclipse editors.  Is there a way we can reduce the number? 
To bring up a runtime workspace, the number of these objects which is created is
quite large, and many seem to be created here:

org.eclipse.swt.custom.StyleRange.clone(StyleRange.java:151)
org.eclipse.jface.text.TextViewer.modelStyleRange2WidgetStyleRange(TextViewer.java:4979)
org.eclipse.jface.text.TextViewer.addPresentation(TextViewer.java:4225)

Is there maybe a way we can reduce the number of temporary StyleRange objects
created?
Comment 1 Dani Megert CLA 2005-04-07 04:46:42 EDT
We will have to investigate.
Comment 2 Billy Biggs CLA 2005-05-03 00:21:33 EDT
I noticed that in DefaultDamagerRepairer#addRange(), it is creating a lot of
StyleRange objects that seem to have all of the fields set to their default
values: null foreground and background, SWT.NORMAL, and no underline or
strikethrough.  Maybe this is an area where the number of objects can be reduced?
Comment 3 Tom Hofmann CLA 2005-05-03 09:53:05 EDT
(In reply to comment #2)
> I noticed that in DefaultDamagerRepairer#addRange(), it is creating a lot of
> StyleRange objects that seem to have all of the fields set to their default
> values: null foreground and background, SWT.NORMAL, and no underline or
> strikethrough.  Maybe this is an area where the number of objects can be reduced?

Trying this out....
Comment 4 Felipe Heidrich CLA 2005-05-03 10:44:50 EDT
Possibily Billy, remember that emtpy StyleRange can be used to reset the 
default colors and font to a range.
Comment 5 Dani Megert CLA 2005-05-25 05:51:21 EDT
Tom, please comment the current state of your findings and what we improved for
the Java editor for 3.1.
Comment 6 Tom Hofmann CLA 2005-05-26 05:01:40 EDT
There are many temporary objects being created during painting. Not sure *how*
bad this really is on current VMs - of course they create garbage, but I thought
that young objects died fast...

A) o.e.jface.text.Region
Everywhere we work text ranges, they are usually represented as an IRegion,
typically implemented by a Region. Evertime something in the document model has
to be mapped to widget coordinates, a new Region is created:

- modelRange2WidgetRange, widgetRange2ModelRange and similar

B) StyleRange
Basically the same as A), but with StyleRanges - this is mainly used by the
presentation framework that handles syntax highlighting, and by the semantic
highlighter. Since the coordinate conversion is still IRegion based, we actually
create two Region instances and one additional StyleRange for every StyleRange
we want to convert.

For 3.1, we changed JavaSourceViewer.modelStyleRange2WidgetStyleRange to not
clone StyleRanges any longer, but simply modify the range that was passed in. We
cannot do this for TextViewer as we cannot modify the implicit contract of a
framework method. However, we could change addTextPresentation to use a
different conversion method that is speced to modify the StyleRanges. Note that
callers of addTextPresentation cannot expect the presentation to remain
unchanged even today, as ITextPresentationListeners are allowed to change the
presentation before it is applied to the widget.

Also, DefaultDamagerRepairer creates many style ranges as said in comment 2.
However, not creating style ranges for ranges that have the default style proved
not easy, as the extent of the created ranges is used to determine the area that
has to be changed on the widget.
Comment 7 Tom Hofmann CLA 2005-12-16 06:25:56 EST
moving back to inbox.
Comment 8 Dani Megert CLA 2005-12-16 11:34:07 EST
*** Bug 96462 has been marked as a duplicate of this bug. ***
Comment 9 Dani Megert CLA 2005-12-16 11:35:52 EST
See also bug 119384.
Comment 10 Dani Megert CLA 2007-11-27 10:56:47 EST

*** This bug has been marked as a duplicate of bug 2537 ***