Bug 486348 - Slow editing of large classes due to inefficient ArrayList access in hot loop reconciling
Summary: Slow editing of large classes due to inefficient ArrayList access in hot loop...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.5.1   Edit
Hardware: All All
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: performance
Depends on:
Blocks:
 
Reported: 2016-01-22 07:44 EST by Lukas Eder CLA
Modified: 2023-02-13 14:18 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lukas Eder CLA 2016-01-22 07:44:29 EST
I've profiled an editing session, where I manipulate large-ish Java files (around 20k lines, lots of overloads, Javadoc, etc.). For the record, these are some examples of such files:

- https://github.com/jOOQ/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/impl/DSL.java
- https://github.com/jOOQ/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/DSLContext.java

The profiler session showed that there seems to be a hot loop that calls:

org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightingReconciler.PositionCollector.addPosition(int offset, int length, Highlighting highlighting)

In this method, we loop over an ArrayList and access elements via List.get(i):


---------------------------------------------------------------
Stack Trace	Sample Count	Percentage(%)
java.util.ArrayList.elementData(int)	545	10.807
   java.util.ArrayList.get(int)	545	10.807
      org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightingReconciler$PositionCollector.addPosition(int, int, SemanticHighlightingManager$Highlighting)	544	10.787
         org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightingReconciler$PositionCollector.visit(SimpleName)	544	10.787
            org.eclipse.jdt.core.dom.SimpleName.accept0(ASTVisitor)	544	10.787
               org.eclipse.jdt.core.dom.ASTNode.accept(ASTVisitor)	544	10.787
                  org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTVisitor, ASTNode$NodeList)	276	5.473
                     org.eclipse.jdt.core.dom.ArrayInitializer.accept0(ASTVisitor)	198	3.926
                     org.eclipse.jdt.core.dom.MethodInvocation.accept0(ASTVisitor)	50	0.991
                     org.eclipse.jdt.core.dom.ClassInstanceCreation.accept0(ASTVisitor)	28	0.555
                  org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTVisitor, ASTNode)	268	5.314
                     org.eclipse.jdt.core.dom.SingleVariableDeclaration.accept0(ASTVisitor)	128	2.538
                     org.eclipse.jdt.core.dom.MethodInvocation.accept0(ASTVisitor)	74	1.467
                     org.eclipse.jdt.core.dom.SingleMemberAnnotation.accept0(ASTVisitor)	27	0.535
                     org.eclipse.jdt.core.dom.MarkerAnnotation.accept0(ASTVisitor)	16	0.317
                     org.eclipse.jdt.core.dom.CastExpression.accept0(ASTVisitor)	8	0.159
                     org.eclipse.jdt.core.dom.QualifiedName.accept0(ASTVisitor)	6	0.119
                     org.eclipse.jdt.core.dom.InfixExpression.accept0(ASTVisitor)	3	0.059
                     org.eclipse.jdt.core.dom.ArrayAccess.accept0(ASTVisitor)	2	0.04
                     org.eclipse.jdt.core.dom.VariableDeclarationFragment.accept0(ASTVisitor)	2	0.04
                     org.eclipse.jdt.core.dom.ReturnStatement.accept0(ASTVisitor)	1	0.02
                     org.eclipse.jdt.core.dom.InstanceofExpression.accept0(ASTVisitor)	1	0.02
---------------------------------------------------------------


If the fRemovedPositions list could be replaced by an array, this loop would perform a lot faster. An alternative might be to loop over the List with a ListIterator.

Of course, these are only suggestions regarding the improvement of the hot loop itself. Perhaps, there is a better algorithm that would avoid this loop from being so hot.

Let me know if you need any additional profiling information, and I will happily provide it.

Also, it appears that this might be the same issue as: https://bugs.eclipse.org/bugs/show_bug.cgi?id=19133
Comment 1 Dani Megert CLA 2016-01-22 08:10:20 EST
(In reply to Lukas Eder from comment #0)
> I've profiled an editing session, where I manipulate large-ish Java files
> (around 20k lines, lots of overloads, Javadoc, etc.). For the record, these
> are some examples of such files:
> 
> -
> https://github.com/jOOQ/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/impl/DSL.java
> 
> -
> https://github.com/jOOQ/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/DSLContext.java

Can you attach a self-contained test project?
Comment 2 Lukas Eder CLA 2016-01-22 09:58:21 EST
It's hard to track it down to a single class or item. I can reproduce this issue when checking out the whole project afresh from GitHub, and then importing it as a new project into Eclipse:

https://github.com/jOOQ/jOOQ/tree/master/jOOQ

From then on, when I open the org.jooq.impl.DSL class, modify it (e.g. by adding whitespace, copy pasting things around, etc.), and saving it, I can see various hot items in a profiler session, among which the call to PositionCollector.addPosition().
Comment 3 Eclipse Genie CLA 2021-02-22 16:27:45 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 4 Eclipse Genie CLA 2023-02-13 14:18:09 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.