This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Why Is Swing Slow?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Why Is Swing Slow??" Watch "Why Is Swing Slow??" New topic
Author

Why Is Swing Slow??

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15292
    
    6

I like Swing. I have been using it for quite some time now and I really don't have any problems with it. I am just asking this our of pure curiosity.
What makes Swing Slow?
Please don't turn this into a pro/anti Swing debate. I like Swing just fine. I just want to know if someone knows.
Thanks.


GenRocket - Experts at Building Test Data
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hello Gregg,
this is an interesting question. I think, the performance of Swing depends on many different little factors starting with the operating system and ending with threads.
At the moment, I work on an interface that loads lots of database rows. First, the interface did wait for all the data from the database and then rendered it. As the data got more and more, the interface "slowed down" of course, as it took longer to get the data and render it. Now, I changed the behaviour to display the data as soon as it comes out of the backend. The search takes as long as before (maybe even longer, as the view has to be updated all the time), but the user does have the impression that it is very quick. In fact, if the gui provides a good and steady feedback it seems to be faster than a gui that has really the same performance but does not provide a steady feedback. (The BeOS gives a very fast graphical feedback to the user, so it seems (and is) lots of times faster than other operating systems.)
Another important point is that the gui does not freeze on backend actions. Multi threading is a fine solution.
ok, this is not really the answer to your question, but it is something I experience all the time: There are many little things that improve the usability and they often seem to accelerate the performance at the same time.
In the time of big CPUs and RAMs and the Hotspot and other neat compilers I think swing is fast enough. But at the same time, the API provides lots of ways for the ignoring programmer (and I certainly am one of those) to slow down a program.
I don't mean that the API is bad but that it provides lots of solutions for one problem and not all of those are good. The net if full of little tips and tricks how to program swing but only part of them are up to date and improve performance.
The source code of the jdk does not really help in many cases. For example: Swing classes still use Vector internally. Vector inherits Collection but they never bothered to add constructors that take a Collection as argument. On the other hand, I found an article (I think even by some Sun people) that recommends to use a HashMap as backing store of a TableModel (and not a Vector as the DefaultTableModel does).
and so on...
cheers
Chantal
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15292
    
    6

Thanks! That was actually quite informative. I would like to know more details about the last part of your post where you talked about Swing classes still using Vector internally and other related information.
For example, I have read that an ArrayList is faster than a Vector, so why doesn't Sun change the underlying API to use an ArrayList instead? Articles or links about that kind of information is what I am looking for.
Also, Is there something what handles the painting of the Components that make slower? Seems like I heard something about this a while back and can't remember where.
Thanks
[ September 20, 2002: Message edited by: Gregg Bolinger ]
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hello Gregg,
ArrayList and LinkedList should be faster than Vector, but they are not thread safe. Use Collections.synchronizedList(new ...List()) to achieve that.
Here are some links on swing performance tuning:
especially JTable: http://java.sun.com/products/jfc/tsc/articles/javaOne2001/1339/index.html
especially JScrollPane (though Blit scroll mode is the default, now, in 1.4.1)
http://java.sun.com/products/jfc/tsc/articles/performance/
Vector, ArrayList, LinkedList:
http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.html
collection of articles on java performance:
http://www.javaperformancetuning.com/tips.shtml
Java Swing performance (threading)
http://billharlan.com/pub/papers/Improving_Swing_Performance.html
for JTable performance, see the source of DefaultTableCellRenderer in 1.4
I believe, the good articles on swing performance tell you how to write good swing code in the first place.
cheers
chantal
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15292
    
    6

Thanks for the links. That will help out quite a bit.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why Is Swing Slow??
 
Similar Threads
GUI performance under 1.5.0
Swing in IE 5
JWS Maintenance issues and future of java on desktop
performance degradation of Swing application on Oracle 10g Application server
Java or .Net for Windows Desktop Apps?