Bug 500332 - Investigate performance improvements to ProgressManager
Summary: Investigate performance improvements to ProgressManager
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.6   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 4.7 M5   Edit
Assignee: Mikaël Barbero CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-26 09:24 EDT by Mikaël Barbero CLA
Modified: 2018-11-27 02:49 EST (History)
6 users (show)

See Also:


Attachments
Heavy progress reporting: differences between fixes for bugs 44502 and 500332 (1.71 MB, video/mp4)
2016-09-01 04:07 EDT, Mikaël Barbero CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mikaël Barbero CLA 2016-08-26 09:24:13 EDT
Here is a list of trails (see bug 445802 comment #79):

1) remove additional thread for notification sending to listeners (use UI thread if listeners don't take longer than about 6ms). Otherwise, keep the additional thread

2) remove all the synchronized blocks, Concurrent data structures, and asyncExecs from those listeners (we can already do that without (1) as they are now called from a single thread)

3) find a way to remove the 'jobs' map from ProgressManager, e.g. by attaching JobInfo to the Job somehow and only access it from the job's thread itself.
Comment 1 Stefan Xenos CLA 2016-08-26 13:40:53 EDT
Regarding 3, we may be able to accomplish this by putting any data structures we need right in the progress monitor, which is attached to the job and only invoked from the job's thread.
Comment 2 Stefan Xenos CLA 2016-08-26 13:43:13 EDT
Regarding 2), I'm not sure you can remove those synchronized blocks yet since we also use a lot of those structures in the UI thread.
Comment 3 Mikaël Barbero CLA 2016-08-26 15:30:45 EDT
(In reply to Stefan Xenos from comment #1)
> Regarding 3, we may be able to accomplish this by putting any data
> structures we need right in the progress monitor, which is attached to the
> job and only invoked from the job's thread.

yep, or I was thinking about Job.setProperty(). Any suggestion about that?


(In reply to Stefan Xenos from comment #2)
> Regarding 2), I'm not sure you can remove those synchronized blocks yet
> since we also use a lot of those structures in the UI thread.

You're right.

I've made an initial test: I invoked everything from the UI thread, and blindly removed all the synchronize blocks and async calls. Even without throttling, the progress reporting is much smoother (looks like ProgressMonitorDialog, without sluggish progress). It does not perform as well as the current version with throttling but I'm confident we can get there with a bit of profiling...
Comment 4 Stefan Xenos CLA 2016-08-26 15:59:11 EDT
> It does not perform as well as the current version with 

Hmm. That would be a very strong argument against my suggestion. IMO, we should do what's fastest. Could I trouble you to attach your test case here so I can profile it, too?
Comment 5 Mikaël Barbero CLA 2016-09-01 04:07:08 EDT
Created attachment 263879 [details]
Heavy progress reporting: differences between fixes for bugs 44502 and 500332

I've managed to do more testing last evening. Using the UI thread (and removing the necessary synchronization) to notify listeners does not provide better performance, but it let us have a *much* smoother reporting. Look at the attached video and look at how the progress are reported on the bottom screen compared to the others. The patch still needs a bit of work, but I plan to submit it by next Monday.
Comment 6 Stefan Xenos CLA 2016-09-01 11:42:15 EDT
From the video it looks like the smoother progress may be a consequence of posting more frequent UI updates, which may explain the why the performance didn't change.

Although it certainly looks a lot smoother, I'd like to review the patch before submission to be sure that we're not creating any UI potential for UI freezes.
Comment 7 Mikaël Barbero CLA 2016-09-05 09:05:17 EDT
I've pushed https://git.eclipse.org/r/#/c/80386/ for early review. This patch does several things that I may need to split into several commits:

- Use the UI thread to notify ProgressManager (PM) listeners
- Remove synchronized blocks / concurrent data structures from listeners
- Remove the unnecessary workbench jobs for refresh (and the concept of infra job at the same time)
- Move the (debug / show all jobs) boolean from the listeners to the PM. 

Please, feel free to comment here or on the patch. Thanks.
Comment 8 Eclipse Genie CLA 2016-09-30 11:10:02 EDT
New Gerrit change created: https://git.eclipse.org/r/82283
Comment 9 Mikaël Barbero CLA 2016-09-30 11:20:11 EDT
I've updated https://git.eclipse.org/r/#/c/80386/ and split the storage of JobInfo in https://git.eclipse.org/r/82283.

I now have performances equivalent between ProgressMonitorDialog and standard Jobs (with bug 445802 comment 1 examples and the benchmarks you've added).
Comment 10 Mikaël Barbero CLA 2016-10-03 08:07:56 EDT
(I'm looking at the failed tests with these latest change sets)
Comment 11 Mikaël Barbero CLA 2016-10-03 09:12:56 EDT
The failing test was assuming everything was done synchronously in the UI thread. With my patch, the listeners are notified with an asyncExec, so we need to queue the assert in the  async queue (this way, the listeners will be notified before the assert is executed).

If the build of patch set 3 is green, I consider these patches good for review :) Thanks.
Comment 13 Ed Merks CLA 2016-12-09 09:16:15 EST
Note that this causes problems with Oomph.

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

Please do not make the platform even harder to reuse without a Workbench instance.  We already have to jump through hoops in way too many places that make such bad assumptions.  E.g., the JobManager or simple filter tree's refresh job.  Obviously we need to use the JobManager in Oomph because p2 uses and it already works poorly without a workbench, which is the reason for this code being there. So please please don't make it even worse.
Comment 14 Mikaël Barbero CLA 2016-12-09 10:33:29 EST
The workbench dependency has been introduced by the usage of PlatformUI#getWorkbench()#getDisplay(). While Display#getDefault() would return the same result in most cases, I can't help to think that depending on the workbench is not inherently wrong from within an internal package in org.eclipse.ui.*workbench* plugin :) Moreover, it is specifically advised in the javadoc to use IWorbench#getDisplay() instead of Display#getDefault()...

I will provide a patch shortly to use Display static factory instead of IWorkbench#getDisplay().
Comment 15 Mikaël Barbero CLA 2016-12-09 11:25:39 EST
I've submitted https://git.eclipse.org/r/86853
Comment 16 Stefan Xenos CLA 2016-12-15 23:10:06 EST
Failures from the latest build:

Regression

org.eclipse.e4.ui.tests.workbench.PartFocusTest.testFocusChangesOnExplicitPartActivation (from org.eclipse.e4.ui.tests.UIAllTests)

java.lang.AssertionError: null
	at org.junit.Assert.fail(Assert.java:86)
	at org.junit.Assert.assertTrue(Assert.java:41)
	at org.junit.Assert.assertTrue(Assert.java:52)
	at org.eclipse.e4.ui.tests.workbench.PartFocusTest.setUp(PartFocusTest.java:134)

org.eclipse.e4.ui.tests.workbench.PartFocusTest.testNoActivationOnExplicitInPartWidgetSelection (from org.eclipse.e4.ui.tests.UIAllTests)

java.lang.AssertionError: null
	at org.junit.Assert.fail(Assert.java:86)
	at org.junit.Assert.assertTrue(Assert.java:41)
	at org.junit.Assert.assertTrue(Assert.java:52)
	at org.eclipse.e4.ui.tests.workbench.PartFocusTest.setUp(PartFocusTest.java:134)
Comment 17 Mikaël Barbero CLA 2016-12-16 02:46:34 EST
Stefan, I don't see the relationship between this bug and test failures from the latest build. Could you please elaborate? Thanks.
Comment 18 Stefan Xenos CLA 2016-12-16 11:18:53 EST
> Stefan, I don't see the relationship between this bug and test
> failures from the latest build.

Neither do I, but I can't give this patch a +2 when it has a long string of failed builds in its recent history. If you can get gerrit to produce a successful build from it, I'll review it.
Comment 19 Mikaël Barbero CLA 2016-12-16 14:55:30 EST
Sorry for the misunderstanding. I thought you were talking about test failures in the latest nightly build of Eclipse (http://download.eclipse.org/eclipse/downloads/) (facepalm). You were referring to https://git.eclipse.org/r/#/c/82283/. 

I agree about not integrating this patch until the build is more stable. I will investigate this further (along with bug 506562).
Comment 20 Mikaël Barbero CLA 2017-01-05 08:35:24 EST
IMO, latest patchset (12) fixes the issue. I've changed the way we keep track of Job managed by the ProgressManager. Previously, it was done by checking whether a JobInfo had been created and put in a Map. This patch forces the creation of JobInfo when the JobMonitor is created. I now only keep a map of managed jobs and JobInfo are always retrieved from the JobMonitor.

The two failures happened in other gerrit builds as well (e.g. https://hudson.eclipse.org/platform/job/eclipse.platform.ui-Gerrit/11607/) so likely unrelated.
Comment 21 Mikaël Barbero CLA 2017-01-09 09:38:25 EST
(In reply to Mikaël Barbero from comment #20)
> The two failures happened in other gerrit builds as well (e.g.
> https://hudson.eclipse.org/platform/job/eclipse.platform.ui-Gerrit/11607/)
> so likely unrelated.

I confirm. The two test failures are unrelated (see bug 505678 comment 13)
Comment 23 Stefan Xenos CLA 2017-02-07 09:18:19 EST
I think this is fixed now, or were there still some follow-ups to address?
Comment 24 Mikaël Barbero CLA 2017-02-07 09:24:09 EST
I think we can consider this as fixed. If any other performance issue is identified, I suggest we track it in another bug. Thanks for your help Stefan.