Fiji hangs because of specific folders in the side bar of the Script Editor

Hey @albertcardona, @ctrueden,

I became a heavy user of the side bar in the script editor - thanks for your efforts on this amazing tool!

I recently observed my script editor becoming slower and slower with time. Specifically, saving macros takes ages (which is strange as save tiny text files on an SSD). This can become worse depending on the length of the list of files in the side bar. Is it possible that some kind of refresh-loop is running updating the GUI when a file is saved?

You can reproduce the issue by executing this macro:

folder = "C:/Users/Rober/Desktop/test/" 

for (i = 0; i < 100; i++) {
	time = getTime();
	File.append("Hello world!", folder + i + ".txt");
	print("Saving took "+ (getTime() - time ));
}

Running it should finish in a second. If you then add the above mentioned folder to the side bar and run the script again, Fiji freezes while having one CPU core on 100%. Actually, you need to utilize the Task Manager to kill Fiji then:

I’m running on Windows 10 with this Fiji/Java, recently updated:
image

I’m happy to help tracing this bug down as it really harms my workflows.

Thanks for your support!

Cheers,
Robert

Hi @haesleinhuepf,

The issue is almost surely in the DirectoryWatcher subclass of the FileSystemTree. Please review its run method here:

https://github.com/scijava/script-editor/blob/1035da4ed37ce48c7b3ea1066e138fd89554d8b5/src/main/java/org/scijava/ui/swing/script/FileSystemTree.java#L555

It may be triggering UI repaint events, or worse, tree update events, for file system events that don’t need it, such as a file growing in size.

Best,

Albert

[https://github.com/scijava/script-editor/blob/1035da4ed37ce48c7b3ea1066e138fd89554d8b5/src/main/java/org/scijava/ui/swing/script/FileSystemTree.java#L555](https://github.com/scijava/script-editor/blob/1035da4ed37ce48c7b3ea1066e138fd89554d8b5/src/main/java/org/scijava/ui/swing/script/FileSystemTree.java#L555)
[https://github.com/scijava/script-editor/blob/1035da](https://github.com/scijava/script-editor/blob/1035da)![image.png|979x599](upload://fltfUzDmz3z9ABpPrtTrLBrUXuT.png)4ed37ce48c7b3ea1066e138fd89554d8b5/src/main/java/org/scijava/ui/swing/script/FileSystemTree.java#L555
2 Likes

In particular line 587 is a terrible mistake: it remakes the list of children of a folder when there’s a change in the files of that folder. Should only listen to deletions and additions, not to any other kinds of changes of the children files!

1 Like

I think I know how to fix it, if I can remember how to launch eclipse and do all the maven yak-shaving.

Here is a pull request: can you test it?

To test it, compile with (edit path):
mvn -Dimagej.app.directory=/path/to/your/Fiji.app/ -Dmaven.test.skip=true clean install

1 Like

Awesome, @albertcardona! This fixed it! Thanks a lot for the immediate response!

Also thanks @ctrueden for merging!

A nice demo of the power of image.sc !

Enjoy the rest of the Sunday!

Cheers,
Robert

Thanks to you both. I released script-editor 0.5.5, and uploaded it to the core update site, and updated pom-scijava (will be part of 29.0.0).

2 Likes

Thanks @haesleinhuepf for testing, very happy to hear this one-liner fix addressed the issue. Been there done that–that kind of bug description makes it all too easy to guess: excessive UI recreation.

On image.sc, indeed, it’s wonderful, because without having to monitor it I get notified when it matters. Thanks @ctrueden for convincing me to use it, and for having set it up and maintaining it!

And thanks also for the quick release of the fixed script editor.

By the way @haesleinhuepf you should hack more into the FileSystemTree, it’s rather straightforward to add features. One feature I’d add is to make it remember by default whatever list of folders are open, without having to use “Save preferences” to make it do so. If you are using it heavily surely you’d come up with additional features.

2 Likes