Bug 242802 - Eclipse hangs for more than 10 seconds when replacing content of large XML file if BasicStructuredDocument is connected
Summary: Eclipse hangs for more than 10 seconds when replacing content of large XML fi...
Status: NEW
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.sse (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 major with 4 votes (vote)
Target Milestone: Future   Edit
Assignee: Nick Sandonato CLA
QA Contact: Nick Sandonato CLA
URL:
Whiteboard:
Keywords: performance
: 136935 143088 422368 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-07-31 19:28 EDT by David Green CLA
Modified: 2019-02-21 07:13 EST (History)
7 users (show)

See Also:


Attachments
heap analysis (41.24 KB, image/png)
2008-07-31 19:32 EDT, David Green CLA
no flags Details
a plug-in that has a single JUnit to exercise the problem (13.37 KB, application/octet-stream)
2008-08-05 14:29 EDT, David Green CLA
no flags Details
mylyn/context/zip (63.79 KB, application/octet-stream)
2008-08-05 14:29 EDT, David Green CLA
no flags Details
memory profiled using visualgc (181.20 KB, image/png)
2008-08-06 12:55 EDT, David Green CLA
no flags Details
profiling results 1 (26.75 KB, image/png)
2008-08-06 13:30 EDT, David Green CLA
no flags Details
profiling results 2 (144.52 KB, image/png)
2008-08-06 13:30 EDT, David Green CLA
no flags Details
heap dump showing excess memory usage (40.09 KB, image/png)
2008-08-06 23:43 EDT, David Green CLA
no flags Details
dominator tree from heap dump showing major offender (80.20 KB, image/png)
2008-08-06 23:44 EDT, David Green CLA
no flags Details
leak hunter report (84.34 KB, image/png)
2008-08-07 00:19 EDT, David Green CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Green CLA 2008-07-31 19:28:18 EDT
Build ID: I20080617-2000

Steps To Reproduce:
Using the resources API, set the content of a large XML file (about 2MB) while the XML editor is open.  Observe poor performance as a result of the DOMModelImpl.nodesReplaced receiving an event with over 100K nodes replaced.  For me Eclipse hangs for about 10 seconds while I'm waiting for processing to complete.

In this case the entire contents of the document was replaced.  Wouldn't it make more sense to call nodesReplaced with the root node of the document?

More information:
To figure out this one I paused the debugger while running a self-hosted eclipse session.  Stack trace from debugger.

Daemon Thread [Thread-2] (Suspended)	
	Character.digit(int, int) line: 4531	
	Character.digit(char, int) line: 4490	
	Integer.parseInt(String, int) line: 454	
	DocumentImpl.getCharValue(String) line: 612	
	TextImpl.getData(IStructuredDocumentRegion) line: 260	
	TextImpl.getData(IStructuredDocumentRegion) line: 240	
	TextImpl.getData() line: 222	
	TextImpl(CharacterDataImpl).getNodeValue() line: 150	
	XMLModelNotifierImpl.valueChanged(Node) line: 484	
	DOMModelImpl.valueChanged(Node) line: 906	
	TextImpl(NodeImpl).notifyValueChanged() line: 627	
	XMLModelParser.removeStructuredDocumentRegion(IStructuredDocumentRegion) line: 2205	
	XMLModelParser.replaceStructuredDocumentRegions(IStructuredDocumentRegionList, IStructuredDocumentRegionList) line: 2338	
	DOMModelImpl.nodesReplaced(StructuredDocumentRegionsReplacedEvent) line: 671	
	JobSafeStructuredDocument(BasicStructuredDocument)._fireEvent(Object[], StructuredDocumentRegionsReplacedEvent) line: 602	
	JobSafeStructuredDocument(BasicStructuredDocument).fireStructuredDocumentEvent(StructuredDocumentRegionsReplacedEvent) line: 1200	
	JobSafeStructuredDocument(BasicStructuredDocument).internalReplaceText(Object, int, int, String, boolean) line: 1979	
	JobSafeStructuredDocument(BasicStructuredDocument).replaceText(Object, int, int, String, boolean, long) line: 2414	
	JobSafeStructuredDocument(BasicStructuredDocument).set(String, long) line: 2930	
	ResourceTextFileBuffer.handleFileContentChanged(boolean, boolean) line: 513	
	ResourceFileBuffer$2.execute() line: 151	
	ResourceFileBuffer$2(ResourceFileBuffer$SafeFileChange).run() line: 86	
	UISynchronizationContext.run(Runnable) line: 34	
	ResourceTextFileBufferManager(TextFileBufferManager).execute(Runnable, boolean) line: 607	
	ResourceFileBuffer$FileSynchronizer.resourceChanged(IResourceChangeEvent) line: 179	
	NotificationManager$2.run() line: 288	
	SafeRunner.run(ISafeRunnable) line: 37	
	NotificationManager.notify(ResourceChangeListenerList$ListenerEntry[], IResourceChangeEvent, boolean) line: 282	
	NotificationManager.broadcastChanges(ElementTree, ResourceChangeEvent, boolean) line: 148	
	Workspace.broadcastPostChange() line: 313	
	Workspace.endOperation(ISchedulingRule, boolean, IProgressMonitor) line: 1022	
	File.setContents(InputStream, int, IProgressMonitor) line: 374	
	File.setContents(InputStream, boolean, boolean, IProgressMonitor) line: 469
Comment 1 David Green CLA 2008-07-31 19:31:17 EDT
I forgot to mention: this is also causing a memory issue.  See attached heap dump analysis
Comment 2 David Green CLA 2008-07-31 19:32:20 EDT
Created attachment 108911 [details]
heap analysis
Comment 3 David Green CLA 2008-08-05 14:29:37 EDT
Created attachment 109203 [details]
a plug-in that has a single JUnit to exercise the problem

Added a JUnit test that can exercise the problem.

To run the JUnit, run Eclipse with the attached plug-in self-hosted (the attachment is an Eclipse plug-in project).  You should see the main menu with 'Bug 242802 Test' added.  Invoke the menu item contained within the menu, and wait for a pop-up.  The assertion should fail and a pop-up informs you that the file contents took > 1000 millis to execute.  On my mac it takes at least 4s, sometimes more than 5s.
Comment 4 David Green CLA 2008-08-05 14:29:41 EDT
Created attachment 109204 [details]
mylyn/context/zip
Comment 5 David Green CLA 2008-08-06 12:55:57 EDT
Created attachment 109332 [details]
memory profiled using visualgc

see annotations in image:

1. test started
2. editor opened
3. file contents replaced
Comment 6 David Green CLA 2008-08-06 13:30:01 EDT
Created attachment 109337 [details]
profiling results 1
Comment 7 David Green CLA 2008-08-06 13:30:27 EDT
Created attachment 109338 [details]
profiling results 2
Comment 8 David Green CLA 2008-08-06 23:43:35 EDT
Created attachment 109370 [details]
heap dump showing excess memory usage
Comment 9 David Green CLA 2008-08-06 23:44:20 EDT
Created attachment 109371 [details]
dominator tree from heap dump showing major offender
Comment 10 David Green CLA 2008-08-07 00:19:04 EDT
Created attachment 109374 [details]
leak hunter report

Seems to be a memory issue.
Comment 11 David Green CLA 2008-08-12 14:53:54 EDT
Attached some screenshots of profiling results.  Note that the file.setContents() portion of the test takes aproximately 50% of the profiled time.

I was wrong about my initial assumption: the DOMModelImpl.nodesReplaced() part of the operation is responsible for about 16% of the CPU time, the other 60% from StructuredPresentationReconciler.processRecordedDamages()
Comment 12 David Green CLA 2008-08-12 14:54:58 EDT
while the profiling shows hot spots in the code, it could be that it's taking so long due to excessive heap utilization.  In cases such as this, garbage collection can take > 80% of CPU time.
Comment 13 Ian Tewksbury CLA 2010-02-05 16:28:16 EST
If memory serves me correctly some fixes have gone into WTP 3.2 to address this issue, but Nick maybe you remember better then myself because I also think it was you who put them in.
Comment 14 Nick Sandonato CLA 2010-04-28 15:15:29 EDT
(In reply to comment #13)
> If memory serves me correctly some fixes have gone into WTP 3.2 to address this
> issue, but Nick maybe you remember better then myself because I also think it
> was you who put them in.

Unfortunately, I'm seeing roughly the same results as David when I run his unit test (which is much appreciated!). We've had some memory improvements and other performance defects but they didn't seem to affect this area of your report.
Comment 15 Nick Sandonato CLA 2012-10-24 17:21:54 EDT
*** Bug 143088 has been marked as a duplicate of this bug. ***
Comment 16 Nick Sandonato CLA 2013-11-25 17:16:26 EST
*** Bug 422368 has been marked as a duplicate of this bug. ***
Comment 17 Nick Sandonato CLA 2014-04-03 10:31:44 EDT
*** Bug 136935 has been marked as a duplicate of this bug. ***
Comment 18 Vasja Pupkin CLA 2019-02-21 07:13:57 EST
Is it still not possible to fix? 
Started : 2008-07-31 19:28 EDT 



Pleeeeease!...