Bug 541047 - Bad performance due to redundant visibleWhen calculations of toolbar contributions
Summary: Bad performance due to redundant visibleWhen calculations of toolbar contribu...
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.10   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2018-11-12 11:53 EST by Sebastian Ratz CLA
Modified: 2020-06-12 08:21 EDT (History)
11 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Ratz CLA 2018-11-12 11:53:06 EST
Follow-up on change 536308.

In ToolBarManagerRenderer, for each and every toolbar contribution that has a visibleWhen expression, a separate context RunAndTrack is scheduled.

It also scales non-linearly, because toolbar contributions also check their children.

The current implementation also adds variables to the central updateVariables Set for which a central RunAndTrack is executed, but never removes them again, leaking unnecessary context updates.

In situation where a lot of context modifications happen, e.g. closing and opening of editors, this can cause thousands and thousands of update calls to the handlers' visibility / enabled state.
Comment 1 Lars Vogel CLA 2018-11-12 12:00:06 EST
Sebastian/ Tobias, knowing you guys, I assume you will attach a patch soon.

Looking forward to review it.
Comment 2 Eclipse Genie CLA 2018-11-12 12:17:13 EST
New Gerrit change created: https://git.eclipse.org/r/132297
Comment 3 Wim Jongman CLA 2018-11-13 07:37:40 EST
(In reply to Eclipse Genie from comment #1)
> Sebastian/ Tobias, knowing you guys, I assume you will attach a patch soon.

(In reply to Eclipse Genie from comment #2)
> New Gerrit change created: https://git.eclipse.org/r/132297

ROFL! 

.. and WeakReference is totally cool. I can't understand how I could have completely missed WeakReference and SoftReference over all those years. I can't recall having ever seen it in Eclipse code.
Comment 4 Sebastian Ratz CLA 2019-01-11 09:22:14 EST
We are not sure whether this approach might break something.

In fact, I am not sure anymore if https://git.eclipse.org/r/#/c/129560/ even is the right approach.

Both changes move the calculation of enabledWhen / visibleWhen outside of the RunAndTrack runnable and therefore detach it from the context.

For a completely imperatively modeled enabledWhen / visibleWhen via e4, which depends on arbitrary values in the IEclipseContext, this might cause the enabled / visible state to be inconsistent.
E.g.:
- Two toolbar buttons
- 1st button sets a value in the IEclipseContext
- 2nd button's visibleWhen depends on that value in the context

I think this never really surfaced as a big problem, because the global RunAndTrack in ToolBarManagerRenderer updates every contribution item on any change of ACTIVE_SELECTION. This happens quite often if the UI is used -- any therefore "repairs" a potentially inconsistent enabled state.

I am not really sure how to go on with this problem -- the whole IEclipseContext is very complex.

Some thoughts on why this is such a big performance problem especially for the ToolBar:
- The toolbar lives in the Window's context
- The items in the toolbar usually depend on information in children of that context, e.g. the active selection in the active context.
- This means that the contributions have to be updated every time the variables active* change in the window context.

@Thomas Schindl
Do you have an idea on how the situation here can be improved while keeping the RunAndTracks and context changes consistent?
Comment 5 Kalyan Prasad Tatavarthi CLA 2019-01-29 08:35:14 EST
My two cents regarding my experience with the changes in this area

1) There are RCP applications which use the API's provided by ToolBarManagerRenderer and any changes here need to be tested with few RCP applications which have toolbar and contribute to the toolbar.(I donot have any sample RCP applicatiosn with me that I can point to.)

2) There are other apps which are built using eclipse and contribute to the toolbar their own menu items. We should be careful not to break their behavior.
I have observed that in such cases, Eclipse toolbar is fine but  the dependent application toolbar is broken. If possible we will need to document what the applications need to do to fix their problem similar to what has been done in Eclipse.

I have not looked at the code. These are my general observations regarding what needs to be taken care of when making major changes to ToolBarManagerRenderer.
Comment 6 Kalyan Prasad Tatavarthi CLA 2019-01-29 08:48:45 EST
(In reply to Kalyan Prasad Tatavarthi from comment #5)
> My two cents regarding my experience with the changes in this area
> 
> 1) There are RCP applications which use the API's provided by
> ToolBarManagerRenderer and any changes here need to be tested with few RCP
> applications which have toolbar and contribute to the toolbar.(I donot have
> any sample RCP applicatiosn with me that I can point to.)
> 
> 2) There are other apps which are built using eclipse and contribute to the
> toolbar their own menu items. We should be careful not to break their
> behavior.
> I have observed that in such cases, Eclipse toolbar is fine but  the
> dependent application toolbar is broken. If possible we will need to
> document what the applications need to do to fix their problem similar to
> what has been done in Eclipse.
> 
> I have not looked at the code. These are my general observations regarding
> what needs to be taken care of when making major changes to
> ToolBarManagerRenderer.

Regarding
> If possible we will need to
> document what the applications need to do to fix their problem similar to
> what has been done in Eclipse.

What I meant here was to document the usage of new API.
Comment 7 Lars Vogel CLA 2019-02-19 03:31:41 EST
Mass change, please reset target if you still planning to fix this for 4.11.
Comment 8 Kalyan Prasad Tatavarthi CLA 2019-05-28 05:43:08 EDT
Please set the target milestone back to 4.12 if you intend to fix this for 4.12.
Comment 9 Lars Vogel CLA 2019-06-12 13:23:30 EDT
Adding Rolf, as he is now the master of visibility for tool items.
Comment 10 Lars Vogel CLA 2020-06-12 05:53:15 EDT
Sebastian, any more work planned here?
Comment 11 Sebastian Ratz CLA 2020-06-12 08:21:54 EDT
Not at the moment, no :(

Changes in this area need to be well-conceived as they have the chance for major side effects.