Bug 553022 - RegistryCSSPropertyHandlerProvider.getCSSPropertyHandlers(): Optimize for 0 and 1 size
Summary: RegistryCSSPropertyHandlerProvider.getCSSPropertyHandlers(): Optimize for 0 a...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.14   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 4.15 M3   Edit
Assignee: Karsten Thoms CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks: 553533
  Show dependency tree
 
Reported: 2019-11-13 16:22 EST by Karsten Thoms CLA
Modified: 2020-01-29 05:21 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karsten Thoms CLA 2019-11-13 16:22:06 EST
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.
Comment 1 Eclipse Genie CLA 2019-11-13 16:36:00 EST
New Gerrit change created: https://git.eclipse.org/r/152619
Comment 2 Karsten Thoms CLA 2019-11-13 17:13:44 EST
The same logic can be applied to
  AbstractCSSEngine.applyStyleDeclaration(Object, CSSStyleDeclaration, String)
Comment 3 Lars Vogel CLA 2019-12-09 08:44:22 EST
How can I measure/ see the improvement?
Comment 4 Karsten Thoms CLA 2019-12-11 08:50:56 EST
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.
Comment 5 Lars Vogel CLA 2019-12-11 09:27:29 EST
(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.
Comment 7 Lars Vogel CLA 2020-01-29 05:16:17 EST
Thanks, Karsten.
Comment 8 Lars Vogel CLA 2020-01-29 05:21:43 EST
(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.