Skip to main content

swing sessions at javaone..

Posted by eitan on June 29, 2005 at 12:34 PM PDT

i've been enjoying some of the desktop talks at javaone
this week. with swing, a common theme for a talk is: tips
and tricks to make swing run faster. so some of these
talks got me thinking..

so here's a problem:

the construction of swing components is an expensive operation.
if you're building a fairly dynamic ui in swing, one where you
create views on the fly, as a response to a user request, then
there is a performance cost to creating the objects that make
up that view.

( an example of such an app may be one that uses
the mdi metaphor: a jdesktoppane with one or more toolbar
panels used to plan or construct representations of objects
on a canvas)

so the typical solution is caching: create views and cache
them in a pool. whenever you need a view you ask the viewmanager
and it might give you a "second hand" view. so the notion
is: don't throw away expensive things; keep them around, you
don't know who might need them later.

the reason i'm writing this is because for swing you have to
roll this out yourself.

i think a generic solution, one that is orthogonal to the application
in question can be arrived at by writing a couple of aspects:
an aspect that overrides new() on swing components to check if
an existing view already exists in the pool and return that
instead. another aspect that intercepts garbage collection and
instead of throwing away the view, cleans it up, dusts it a little,
and puts it back in the pool or "reuse bin," so to speak.

this reminds me of a recent talk that my friend bruce tate
gave to our users group in austin, texas, that touched on dynamic
languages such as ruby. in ruby, the ability to intercept such
calls is intrinsic to the language, and so injecting such a feature
turns out to be a simpler task for the developer.

the reason i write this is that i'm lazy.
i want this feature, so that i can improve the performance of my swing
applications. but this is a generic concern. maybe there's
something already out there, maybe throwing the idea in the
communal pot can help trigger the creation of a new java.net
project. who knows?

Related Topics >>