Bug 565166 - [organize imports] Run on UI Thread and freeze UI for large project
Summary: [organize imports] Run on UI Thread and freeze UI for large project
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.9   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 4.17 M3   Edit
Assignee: Roland Grunberg CLA
QA Contact: Roland Grunberg CLA
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks: 563542
  Show dependency tree
 
Reported: 2020-07-13 02:38 EDT by GILLES Hélios CLA
Modified: 2020-09-08 02:36 EDT (History)
4 users (show)

See Also:


Attachments
Screenshot (18.84 KB, image/png)
2020-09-08 02:36 EDT, Lars Vogel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description GILLES Hélios CLA 2020-07-13 02:38:28 EDT
The "Organize Imports" command run on UI Thread and this lead to a possible long (> 1 minute)  UI freeze for large project beeing indexed.

This UI freeze occurs when Thread.sleep is called in JobManager.performConcurrentJob to wait "Java indexing" for completion.

Maybe it's possible tu run "Organize Imports" command in "Worker-Thread" for not freezing UI.
Comment 1 Roland Grunberg CLA 2020-07-15 13:56:07 EDT
Note that OrganizeImportsOperation is located in jdt.core.manipulation so the entire modification of the compilation unit can be done outside of UI code.

After playing around with IProgressService.run(..), JavaCore.run(..) and various other things that didn't seem to have the desired effect, I settled on the Job API. I've attached a patch that seems to fix things. I added a 15s wait in OrganizeImportsOperation to simulate a long run. Note that you can navigate and even make other edits in the file while OrganizeImportsOperation runs. I think setting a scheduling rule should still be done so that attempting to save while the operation is running forces the progress bar to come out, indicating that another operation is in progress.
Comment 2 Eclipse Genie CLA 2020-07-15 15:32:28 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/166361
Comment 3 GILLES Hélios CLA 2020-07-16 05:11:26 EDT
Tested and ok for me. Thx !
Comment 4 Noopur Gupta CLA 2020-07-16 05:25:05 EDT
(In reply to Roland Grunberg from comment #1)
> Note that OrganizeImportsOperation is located in jdt.core.manipulation so
> the entire modification of the compilation unit can be done outside of UI
> code.
> 
> After playing around with IProgressService.run(..), JavaCore.run(..) and
> various other things that didn't seem to have the desired effect, I settled
> on the Job API. I've attached a patch that seems to fix things. I added a
> 15s wait in OrganizeImportsOperation to simulate a long run. Note that you
> can navigate and even make other edits in the file while
> OrganizeImportsOperation runs. 

Sounds good.

> I think setting a scheduling rule should
> still be done so that attempting to save while the operation is running
> forces the progress bar to come out, indicating that another operation is in
> progress.

Yes.

Andrey, can you please take a look and let us know if you see any potential issues?
Comment 5 Andrey Loskutov CLA 2020-07-16 05:42:14 EDT
(In reply to Noopur Gupta from comment #4)
> Andrey, can you please take a look and let us know if you see any potential
> issues?

I've commented on review.
Comment 6 Noopur Gupta CLA 2020-07-16 05:43:58 EDT
(In reply to Andrey Loskutov from comment #5)
> I've commented on review.
Thanks, Andrey.
Comment 8 Roland Grunberg CLA 2020-08-18 16:49:41 EDT
Verified for 4.17 M3 using I20200818-0900 build
Comment 9 Lars Vogel CLA 2020-09-08 02:36:02 EDT
Created attachment 284076 [details]
Screenshot

Roland, should that fix also work for the save action? I still get from time to time the Slow Save Actions popup due to organize imports, see screenshot in Eclipse SDK
Version: 2020-12 (4.18)
Build id: I20200904-0540
OS: Linux, v.5.4.0-45-generic, x86_64 / gtk 3.24.20, WebKit 2.28.4
Java version: 14