Bug 66026 - Large amount of garbage created by DefaultCommentMapper
Summary: Large amount of garbage created by DefaultCommentMapper
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: 3.0 RC2   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks: 66463
  Show dependency tree
 
Reported: 2004-06-07 14:20 EDT by John Arthorne CLA
Modified: 2004-06-11 12:18 EDT (History)
1 user (show)

See Also:


Attachments
Reverse allocation backtrace showing origin of two separate reconciles (21.83 KB, text/html)
2004-06-07 14:22 EDT, John Arthorne CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description John Arthorne CLA 2004-06-07 14:20:55 EDT
Build: I20040607

Steps:

1) Checkout org.eclipse.core.runtime from dev.eclipse.org
2) Close all perspectives
3) Open Resource perspective
4) Close all views
5) Customize perspective to add "Open Type" command
6) Ctrl+Shift+T
7) Type "Path"
8) Hit ok
9) Wait for CPU to settle down, then close editor
10) Ctrl+Shift+T
11) Type "Path"

-> Start Heap profiler

12) Click ok

-> After activity stops, stop profiler

In this test, DefaultCommentTracker creates:

 - 5996 instances of DefaultCommentTracker
 - 5996 instances of ArrayList
 - 6012 instances of Object[]

All of this garbage is created by the visitor itself. The code is implemented 
using a recursive method (doExtraRangesForChildren). On each recursive step, 
it creates a visitor to visit and collect the children of each node.

Couldn't this be implemented by a single AST visitor, rather than a recursive 
method that creates a new visitor for each node?

Note: The entire reconcile seems to happen TWICE in this scenario. I will 
attach an allocation backtrace that shows how this happens.
Comment 1 John Arthorne CLA 2004-06-07 14:22:17 EDT
Created attachment 11677 [details]
Reverse allocation backtrace showing origin of two separate reconciles
Comment 2 Philipe Mulet CLA 2004-06-07 15:47:39 EDT
Must fix.
Comment 3 Frederic Fusier CLA 2004-06-09 14:31:44 EDT
Fixed.

Rewrite visitor of DefaultCommentMapper to avoid unnecessary initialization.
Also optimize trailing comments to avoid scan after node end position when node
has same end position than its parent...
Also avoid unnecessary instanciation of DefaultCommentMapper while converting
javadoc for dom ast hierarchy

[jdt-core-internal]
Changes done in DefaultCommentMapper + ASTConverter
No test cases added: existing massive test DefaultCommentMapperTests run on all
eclipse java files validated that change has no impact on heuristic result...

I will quantify more precisely memory + GC + time gain with this new
implementation and dump results in this bug tomorrow...
Comment 4 Philipe Mulet CLA 2004-06-09 16:12:26 EDT
New visitor is only doing one traversal, with a map to record pending child. 
It is relying on deferring the computation of extended source range until it 
traverses a sibling of a node (recorded as pending until traversing a 
subsequent node with same parent, then parent processes last pending child 
when doing #endVisit).
We should investigate post 3.0 using the same approach we took for source ends 
(-1 if same as parent end), to optimize source starts to rely on parent 
extended source range. 
Comment 5 Frederic Fusier CLA 2004-06-10 01:40:33 EDT
Using YourKit Java Profiler I got following memory result:
Before fix:
                                        GCed Objects   GCed Size (bytes)
DefaultCommentMapper                           11250     359,056
DefaultCommentMapper$ChildrenCollector          6004     241,056

After fix:
                                        GCed Objects   GCed Size (bytes)
DefaultCommentMapper                            3713     101,424
DefaultCommentMapper$CommentMapperVisitor       1494      56,920

Which represents a down size of 73.6% for garbaged allocated memory while
opening Path.java file.
Comment 6 David Audel CLA 2004-06-11 12:18:31 EDT
Verified for 3.0RC2 I20040611