Community
Participate
Working Groups
The CSS engine will call the getCSSPropertyHandlers() very frequently during styling. At the beginning a new ArrayList is instantiated. This is wasting resources, since the resulting collection will always be of size 0 or 1. This can be optimized by returning Collections.emptyList() when no handler is returned and a Collection.singletonList() when one handler was found. For the case that more than one handler is collected, the singleton list cann be replaced by an ArrayList. Further, the singletonLists don't need to be created with each call, they can be cached per handler instance. By doing this, no unnecessray lists are created.
New Gerrit change created: https://git.eclipse.org/r/152619
The same logic can be applied to AbstractCSSEngine.applyStyleDeclaration(Object, CSSStyleDeclaration, String)
How can I measure/ see the improvement?
Waste of short-time allocated memory is a bit hard to profile. The lists are used only locally, so they are allocated and collected immediately. I think I stumbled when I looked for potential in ThemeEngine#applyStyles, which is called during startup. There I saw that one of the most called methods is RegistryCSSPropertyHandlerProvider.getCSSPropertyHandlers(Object, String) This method takes the given Object's class and will return the same result for given combination of the class and the property name. This is a limited number of combinations, making it a candidate for caching. When you debug the 'handlers' result list's size, you'll see it is always 1. The CSS engine potentially allows multiple handlers for a style, but that's not the normal case. If you debug into the getCSSPropertyHandlers() method you'll see that this is not only called during startup, but always. However, it will be a rather minor effect.
(In reply to Karsten Thoms from comment #4) > Waste of short-time allocated memory is a bit hard to profile. The lists are > used only locally, so they are allocated and collected immediately. > > I think I stumbled when I looked for potential in ThemeEngine#applyStyles, > which is called during startup. There I saw that one of the most called > methods is > > RegistryCSSPropertyHandlerProvider.getCSSPropertyHandlers(Object, String) > > This method takes the given Object's class and will return the same result > for given combination of the class and the property name. This is a limited > number of combinations, making it a candidate for caching. When you debug > the 'handlers' result list's size, you'll see it is always 1. The CSS engine > potentially allows multiple handlers for a style, but that's not the normal > case. > > If you debug into the getCSSPropertyHandlers() method you'll see that this > is not only called during startup, but always. However, it will be a rather > minor effect. Thanks, I test now in the debugger.
Gerrit change https://git.eclipse.org/r/152619 was merged to [master]. Commit: http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=a150fc3111f4d7922850fcfff2a835e4aad216a9
Thanks, Karsten.
(In reply to Karsten Thoms from comment #2) > The same logic can be applied to > AbstractCSSEngine.applyStyleDeclaration(Object, CSSStyleDeclaration, > String) Did you also fix that? Can't find a Gerrit for it.