Bug 558227 - AbstractCSSEngine is really inefficent (could be only windows)
Summary: AbstractCSSEngine is really inefficent (could be only windows)
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.12   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: 4.15 M1   Edit
Assignee: Johan Compagner CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks: 533828 553533
  Show dependency tree
 
Reported: 2019-12-11 09:49 EST by Johan Compagner CLA
Modified: 2020-04-13 08:14 EDT (History)
3 users (show)

See Also:


Attachments
here you see a yourkit profile where 6 seconds is just there.. (250.29 KB, image/jpeg)
2019-12-11 09:49 EST, Johan Compagner CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Johan Compagner CLA 2019-12-11 09:49:38 EST
Created attachment 281200 [details]
here you see a yourkit profile where 6 seconds is just there..

https://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/engine/AbstractCSSEngine.java#n426

that line calls in a for loop constantly getLength()
that results in very bad behavior on windows, this is my stack:

Thread [main] (Suspended)	
	LessPropertiesComposite$1(Composite)._getChildren() line: 103	
	LessPropertiesComposite$1(Composite).getChildren() line: 470	
	LessPropertiesComposite$1.getChildren() line: 159	
	CompositeElement.getLength() line: 37	
	CSSSWTEngineImpl(AbstractCSSEngine).applyStyles(Object, boolean, boolean) line: 428	
	CSSSWTEngineImpl(AbstractCSSEngine).applyStyles(Object, boolean) line: 358	
	CSSSWTEngineImpl(AbstractCSSEngine).applyStyles(Object, boolean, boolean) line: 429	
	CSSSWTEngineImpl(AbstractCSSEngine).applyStyles(Object, boolean) line: 358	
	CSSSWTEngineImpl(AbstractCSSEngine).applyStyles(Object, boolean, boolean) line: 429	
	CSSSWTEngineImpl(AbstractCSSEngine).applyStyles(Object, boolean) line: 358	
	CSSSWTEngineImpl(AbstractCSSEngine).applyStyles(Object, boolean, boolean) line: 429	
	CSSSWTEngineImpl(AbstractCSSEngine).applyStyles(Object, boolean) line: 358	
	CSSSWTEngineImpl(AbstractCSSEngine).applyStyles(Object, boolean, boolean) line: 429	
	CSSSWTEngineImpl(AbstractCSSEngine).applyStyles(Object, boolean) line: 358	
	CSSSWTEngineImpl(AbstractCSSEngine).applyStyles(Object, boolean, boolean) line: 429	
	CSSSWTEngineImpl(AbstractCSSEngine).applyStyles(Object, boolean) line: 358	
	ThemeEngine.applyStyles(Object, boolean) line: 543	

that 
LessPropertiesComposite$1.getChildren() line: 159

is my code that does nothing more then a super call to see how often that is called (and the numbers are enormous)

Problem is that in the end _getChildren() is constantly creating a array with all the children and for windows it calls also quite a bit of native code.

here you can see that more have this problem:

https://stackoverflow.com/questions/58451881/eclipse-4-ui-slow-css-engine-called-too-often-windows

when i do this in my overwritten getChildren() method:

	public Control[] getChildren()
			{
				if (children == null)
				{
					children = super.getChildren();
				}
				return children;
			}

it suddenly way way more faster..
Problem is that that composite has many components (up to 400 or so) because it is a special editor with a lot of label, textfield, button combinations
Comment 1 Lars Vogel CLA 2019-12-11 09:55:58 EST
Cool, Johan, could you please provide a Gerrit patch for that change? See https://www.vogella.com/tutorials/EclipsePlatformDevelopment/article.html#exericse-eclipse-user-creation-and-gerrit-server-configuration

Gerrit setup usually take ~10-15 min. Lets me know if you have questions.
Comment 2 Lars Vogel CLA 2019-12-11 09:59:07 EST
Johan, a issue that sounds similar is handled by https://git.eclipse.org/r/c/152619
Comment 3 Johan Compagner CLA 2019-12-11 10:10:41 EST
dont think it is touched in that specific gerrit patch at least i don't see it as a change

because the change is quite simple instead of doing:

for (int k = 0; k < nodes.getLength(); k++) {
								applyStyles(nodes.item(k), applyStylesToChildNodes);
							}

do

int length = nodes.getLength();
for (int k = 0; k < length; k++) {
								applyStyles(nodes.item(k), applyStylesToChildNodes);
							}


or go from length to 0, no idea if that is even better or not...

We don't expect that nodes.getLength() suddenly changes right? That would be very weird..
Comment 4 Lars Vogel CLA 2019-12-11 10:14:46 EST
(In reply to Johan Compagner from comment #3)

> We don't expect that nodes.getLength() suddenly changes right? That would be
> very weird..

I would also not expect that, please upload a Gerrit so that we can test and integrate it. Thanks for helping here Johan!
Comment 5 Johan Compagner CLA 2019-12-11 10:24:56 EST
hmm i need to check a bit more
Because the problem is also a bit in CompositeElement ...

because if i just adjust the calls to getLength() in 3 places in AbstractCSSEngine  then that is a nice thing to do 

but then the next line: nodes.item(k) does it again

So i think the CompositeElement needs to cache the children, let me look if that is possible.
Comment 6 Eclipse Genie CLA 2019-12-11 11:21:21 EST
New Gerrit change created: https://git.eclipse.org/r/154336
Comment 7 Johan Compagner CLA 2019-12-11 11:24:38 EST
That was a bit more tricky then first thought..

So now NodeList implementors like CompositeElement  can implement a new interface IStreamingNodeList

For now i let only CompositeElement do that. but i think for example CTabFolderElement could also benefit from that.
Comment 8 Johan Compagner CLA 2019-12-11 11:57:10 EST
there is a problem at jenkins/hudson i guess:

Caused by: java.io.IOException: No space left on device
Comment 9 Karsten Thoms CLA 2019-12-11 12:57:17 EST
Thanks Johan for submitting the patch to Gerrit. The build server problem will be solved soon by the EFdn staff. We'll look at your patch soon.
Comment 11 Lars Vogel CLA 2019-12-16 15:20:07 EST
Thanks Johan for the patch. I hope we see more patches from you.
Comment 12 Johan Compagner CLA 2019-12-17 03:36:51 EST
(In reply to Lars Vogel from comment #11)
> Thanks Johan for the patch. I hope we see more patches from you.

i still have one ;)

https://bugs.eclipse.org/bugs/show_bug.cgi?id=533828

Now i constantly just patch that plugin and with mvn i inject it into the local repo over the one that is already there, so get a patched version in our product:
https://github.com/Servoy/servoy-eclipse/blob/master/org.eclipse.help.ui/pom.xml#L44
Comment 13 Lars Vogel CLA 2019-12-17 11:40:35 EST
(In reply to Johan Compagner from comment #12)
> (In reply to Lars Vogel from comment #11)
> > Thanks Johan for the patch. I hope we see more patches from you.
> 
> i still have one ;)
> 
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=533828
> 
> Now i constantly just patch that plugin and with mvn i inject it into the
> local repo over the one that is already there, so get a patched version in
> our product:
> https://github.com/Servoy/servoy-eclipse/blob/master/org.eclipse.help.ui/pom.
> xml#L44

Thanks, will merge today.

Please provide more patches if you can. We love cleanup, performance and API improvement patches as well as new functionality and hopefully your product can benefit from a better platform.