Bug 535681 - Staging view updates UI even when not visible
Summary: Staging view updates UI even when not visible
Status: NEW
Alias: None
Product: EGit
Classification: Technology
Component: UI (show other bugs)
Version: 5.0   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-08 06:20 EDT by Ed Willink CLA
Modified: 2021-06-09 10:16 EDT (History)
3 users (show)

See Also:


Attachments
JProfiler screenshot while Staging View is updating tree view with 9000 items (121.08 KB, image/png)
2020-06-22 11:54 EDT, Michael Haubenwallner CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Willink CLA 2018-06-08 06:20:18 EDT
Bug 535516 demonstrated that the GIT staging view is updated, very slowly, on the UI thread. The very slowly was fixed, but the premature UI lockout from updating a not-visible view was not.

The GIT Staging View should NOT consume possibly non-trivial UI thread cycles when NOT visible.
Comment 1 Thomas Wolf CLA 2018-06-08 06:26:54 EDT
Updating the UI may take some time (especially when thousands of changes suddenly appear as unstaged) and has the potential to block the user.

Would be nice if that could be avoided, unless the user actually can see the view -- in that case we _have_ to update the UI.
Comment 2 Ed Willink CLA 2018-06-08 11:57:25 EDT
(In reply to Thomas Wolf from comment #1)
> Updating the UI may take some time (especially when thousands of changes
> suddenly appear as unstaged) and has the potential to block the user.

Potential, but there are solutions. For instance if in the standard Search View you do a search that find tens of thousands of results e.g. "http", the search results grow as results are found. The Search View shows an executing cursor. The other views are not frozen.
Comment 3 Thomas Wolf CLA 2019-06-30 16:25:15 EDT
Technical notes: appears that this may occur in particular on IndexDiffChanges. Selection tracking already handles view visibility.
Comment 4 Michael Haubenwallner CLA 2020-06-22 11:54:35 EDT
Created attachment 283378 [details]
JProfiler screenshot while Staging View is updating tree view with 9000 items

Similar issue here:
Staging View does contribute more than 20 seconds to the Eclipse UI lock, when the input for the Staging View is getting updated (but not necessarily changed), for example by saving some additional change to some java file.

Here, the git repository in question does consist of ~67000 files distributed to ~630 projects, with ~9000 files currently having Unstaged Changes.

It turns out that the Staging View does initialize text and image to each of the ~9000 items into the TreeView, even if most of them never become actually visible.
In total, the most expensive part here is in StagingEntry.getFile(), because for each of the ~9000 files, FileSystemResourceManager.resourceForLocation() does iterate over all ~630 projects to find some best matching project.

Although I'm pretty new to Java and Eclipse, to me it should be possible to reduce the tree update time in general by using "virtual" tree views, and I have drafted something to see whether this may help:
https://git.eclipse.org/r/c/165047

What do you think?
Comment 5 Thomas Wolf CLA 2020-06-22 12:55:08 EDT
(In reply to Michael Haubenwallner from comment #4)
> Created attachment 283378 [details]
> JProfiler screenshot while Staging View is updating tree view with 9000 items
> 
> Similar issue here:
> Staging View does contribute more than 20 seconds to the Eclipse UI lock,
> when the input for the Staging View is getting updated (but not necessarily
> changed), for example by saving some additional change to some java file.
> 
> Here, the git repository in question does consist of ~67000 files
> distributed to ~630 projects, with ~9000 files currently having Unstaged
> Changes.
> 
> It turns out that the Staging View does initialize text and image to each of
> the ~9000 items into the TreeView, even if most of them never become
> actually visible.
> In total, the most expensive part here is in StagingEntry.getFile(), because
> for each of the ~9000 files, FileSystemResourceManager.resourceForLocation()
> does iterate over all ~630 projects to find some best matching project.
> 
> Although I'm pretty new to Java and Eclipse, to me it should be possible to
> reduce the tree update time in general by using "virtual" tree views, and I
> have drafted something to see whether this may help:
> https://git.eclipse.org/r/c/165047
> 
> What do you think?

You've picked a hard problem. Some thoughts:

* The fact that this takes a lot of time is actually unrelated to the issue of
  this bug. (Though of course that it happens even when view is not visible
  isn't nice.)
* Virtual trees may come with their own set of problems and bugs. The
  CommitFileDiffViewer (for instance bottom right in the history view) uses a
  virtual table, and we struggled quite a bit to make it perform for huge
  commits.
* The selection handling when files are staged/unstaged is highly complicated,
  and may mean that all tree nodes get realized anyway.
* To get decoration overhead out of the main thread: can these viewers be made
  to use a lightweight background decorator for all their decorations, or at
  least for the problem decoration?
* (Small optimization) StagingEntry.getProblemSeverity() could return
  Severity.NONE right away if the state is REMOVED, MISSING, or
  MISSING_AND_CHANGED?
* To reduce the number of calls to resourceForLocation() is there some way that
  we could cache project paths as we go, and subsequently look up projects in
  that cache first? If a project location is a prefix of the file location,
  the file should be in that project, and then determining the file via
  IProject.getFile() and checking if it exists may be faster.
* According to your screenshot, the ProblemLabelDecorator accounts for some 30% 
  of the time. Creating the tree items themselves also appears to be expensive,
  plus setting their images and texts (together another 30%). So perhaps a
  virtual tree is the way to go, but don't expect it to be easy.
* Careful testing on all three platforms (Windows, GTK, OS X) will be needed.
Comment 6 Michael Haubenwallner CLA 2020-06-23 04:45:30 EDT
(In reply to Thomas Wolf from comment #5)
> (In reply to Michael Haubenwallner from comment #4)
> > 
> > Similar issue here:
> > Staging View does contribute more than 20 seconds to the Eclipse UI lock,
> > when the input for the Staging View is getting updated (but not necessarily
> > changed), for example by saving some additional change to some java file.

> * The fact that this takes a lot of time is actually unrelated to the issue
>   of this bug. (Though of course that it happens even when view is not visible
>   isn't nice.)

Agreed: Not updating the invisible view may make sense even if there were no performance issue.
I've forked the general performance issue into bug 564569.