mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.13k stars 234 forks source link

File chooser creation is quite slow #140

Open Sorceror opened 10 years ago

Sorceror commented 10 years ago

I like WebLaF for lots and lots of nice features, but currently rewriting some GUI parts of one project to WebLaF using advanced features (like pretty tooltips, notifications, etc.) and I just noticed that selecting a file is quite slow. So I made some small tests and find out that creation (first is the slowest) of JFileChooser/WebFileChooser tooks about 2.5s, which is already noticeable.

Here is some SSCCE

long start = System.currentTimeMillis();
JFileChooser fileChooser = new JFileChooser();
System.out.println("Took " + ((System.currentTimeMillis() - start) / 1000d) + " sec to create default file chooser");
fileChooser.showDialog(null, "Choose");

WebLookAndFeel.install();
start = System.currentTimeMillis();
fileChooser = new JFileChooser();
System.out.println("Took " + ((System.currentTimeMillis() - start) / 1000d) + " sec to create weblaf file chooser");
fileChooser.showDialog(null, "Choose");

My resutls on Win 8, Java 1_8_05 (64bit)

Took 0.451 sec to create default file chooser
Took 2.437 sec to create weblaf file chooser
mgarin commented 10 years ago

I am having something like this:

Took 0.417 sec to create default file chooser
Took 0.795 sec to create weblaf file chooser

This time depends on the loading of the file tree and list/table elements plus their first-time visual representation (icons, name, size etc.). Standard JFileChooser doesn't have file thumbnails and doesn't use such information so yes, it loads faster due to lesser amount of UI elements and information loaded from hard drive.

By the way, probably there is such a big difference in time between our result due to the hard drive speed and type, for example I've got an SSD here.

mgarin commented 10 years ago

Though I will be doing some optimizations to WebFileChooserUI later, so probably the load speed will get improved with time, but not too much.

Sorceror commented 10 years ago

Thanks for this a lot other neat features in WebLaF. Though maybe the biggest bottleneck on my machine is the external usb disk which is touched by the file chooser, also second run of the file chooser is much quicker (probably due fact that icons are already cached).

mgarin commented 10 years ago

Yes, USB can really hang for a while. And the second run is always fast due to many factors, not just the icons initialization or file structure cached.

Probably if opening file chooser right away when user requests it is critical for you - you might want to call new WebFileChooser() while application is loading (or simply create the instance which you will use later at the initialization. That might help a bit.