Java theory and practice: Urban performance legends, revisited

I don’t comment very often on java performance myth busting articles anymore (I used to do this a lot at slashdot and the javalobby). However, this: Java theory and practice: Urban performance legends, revisited is an exceptionally good and informative article that focuses on memory management. The article explains how both memoray allocation and deallocation and stack usage vs heap usage are smarter in Java then with the default C/C++ mechanisms for memory allocation.

Of course the issue is that whereas there are a lot of performance myths, it is also undeniably true that many Java desktop applications are perceived as slow. On the server the debate is pretty much over. Not in the least because C/C++ is not very suitable for building secure network applications for reasons which have a lot to do with how memory is managed (or rather not managed) in C/C++. All the competing server languages are either interpreted or dynamically compiled.

There are a lot of myths about dynamic compilation too. A lot of people state that “because java is interpreted it will always be slower than a compiled language”. Such statements are usually based on a poor understanding of compiler technology.

In short, a compiler is a program that translates a program to running code. A dynamic compiler does this at the latest possible/convenient time (after starting the program, before executing the code). A static compiler on the other hand does this before the program is started.

So why is the above statement wrong: a dynamic compiler has the same bag of tricks to make code run fast that a static compiler has. Wait that’s not true either: it has a larger bag of tricks because it can observe the code while it is running and optimize for the runtime conditions. All this requires some overhead of course: a minor static effort to do simple compilation + whatever optimizations are worthwhile to do (this to can be determined dynamically).

On modern computer systems, there is plenty of time for this. Proportional to the total cpu time used, the overhead for compilation and optimization is neglegible. Only in constrained environments such as low end mobile phones this is not (yet) true. High end phones on the other hand are already much faster than the PCs I used to do swing development on in 1998!

So memory management and dynamic compilations are the source of many performance myths and yet are also arguably making Java a faster environment than plain old C/C++. So where does the slowness come from. It has a lot to do with program design and library design.

Java makes it easy to do things that used to be really difficult (IO, threading, databases). But you need to know what you are doing to make it perform well.

Especially when trying to make a GUI application, a lot of these things tend to come together. If the application freezes a lot (a common complaint), that is not because java is garbage collecting but because the developer did not understand threading. If the application uses a lot of memory, the reason is probably that it is allocating a lot of it (duh). If that’s a problem, good developers have a large bag of tricks at their disposal to detect and fix memory issues.


Google has a new thingy: Reader.
Seems like a nice RSS reader. It only has one major issue: it is a bit slow. But I suppose it is nice to have a tool like this for on the road. Otherwise, I am happy using Sage.

iTunes review

After about a day of intensive use of iTunes (, win32) I have decided to stick with it for a while. However, I’m not entirely happy with it yet and I’ll list my detailed criticism here.

1) It looks nice but it is not very responsive. Especially not when managing the amounts of music the ipod is intended for. I am talking about the noticable lag when switching from one view to another, the lack of feedback what is doing when, apparently, it can’t respond right away to any mouse clicks.

2). I am used to winamp which has a nerdy interface but gets several things right in the media library that iTunes doesn’t. The most important thing, the notion of a currently playing list of songs, is missing. That means that if you are navigating your songs, you are also editing the list of songs that is currently playing (unless you are playing a playlist in a seperate window). This is extremely annoying because this means you can’t play albums and browse your other music at the same time which is the way I prefer to listen to my music.

Steps to reproduce: put the library in browse mode (so you can select artist and than album), select one of your albums, start playing the first song. Browse to some other album, click the next button. Instead of playing track 2 of the album you were listening to (IMHO the one and only desired behavior) you were playing the music stops because by now a different set of files is selected.

A solution (or rather workaround) to this would be to create playlists for each album and play those. This cannot be done automatically. I have 300+ albums. You can drag m3u files (a common playlist format that simply lists the files in the order they should be played) to itunes (good) but if you drag more than one it merges them into one big playlist (bad).

3) So if you have m3u files for your albums or other playlists, you still need to import them one by one. That sucks.

An alternative solution would be to treat albums as playlists when clicked upon.

The best solution is of course to do it like winamp. Until you start to play something new the player plays whatever is in its current playlist. If you click an album, that becomes the current playlist. So simple, intuitive and yet missing. Of course it contradicts with the misguided notion of putting checkboxes in a list of 5000 files. The browse mode sort of covers up for this design error by automatically unchecking everything hidden by the browser. That’s why your album is unchecked when you select another album.

I can guess why apple chooses to not fix this issue. It requires changing the user interface to add a list of currently selected songs. This product is for novice users and adding user interface elements makes it more complex. Incidently the ipod is much smarter! It doesn’t change the current selection until you select something new and browsing is not the same as selecting!

4) Double clicking a playlist opens a new window! The idea of a playlist is to play one song after another (like I want to do with my albums). Effectively the playlist becomes the active list once you start playing it. However, as discussed above, iTunes does not have a concept of a current playlist so they ‘fixed’ it by opening a new window. IMHO this is needlessly confusing (for windows users, I understand multiple application windows is something mac users are more used to).

5) Of course this conflicts with the minimize to traybar option which only works for the main window. You can also play playlists like albums but then you encounter issue number 2 again. Conclusion Apple’s fix for issue number 2 is a direct cause for number 4 (serious usability issue) and this issue.

6) A separate issue is album art. Many users have file based mp3 players like winamp which store album art as a separate folder.jpg file in the directory the album mp3s are in. iTunes has an album art feature but will ignore those files. Worse the only way to add album art is to add the image to each individual music file (so if your album is fifteen tracks, the same image must be added to fifteen files). Aside from the waste of diskspace (or worse flash drive space), this is just to cumbersome to manage. I found a neat tool that can automate fetching and adding album art for albums.

7) Finally some issues with the help system. I normally do not refer to help files unless I need them. A day of using iTunes has forced me to do this several times because the user interface has a lot of obscure buttons and options that are not always self explaining. For example the menu option “consolidate library” sounds rather scary and, as I found out by reading the help file, you probably don’t want to click it. Another beautiful option is “group compilations when browsing”. This is a bit harder to figure out because the help search feature returns one result for ‘compilation’ which is a huge list of tips.

The problem: the help information is not organized around the userinterface like it should be. Task based documentation is nice to have but not if you are looking for information on button X in dialog Y.

So why do I still continue to use it: it is integrated in a clever way with my ipod 🙂 and I hope to find some solutions to the problems above using 3rd party tools. Ipod integration seems to work rather nicely, just plug it in and it synchronizes. I have the big version with plenty of space so I just want everything I have to be sycnhronized to it and this seems to work well. Except for one thing:

8) Apparently I have songs that the ipod can’t play that itunes can play. The synchronization process warns of this by telling me it can’t play some songs but fails to inform me which ones (so I can’t fix it)! The obvious solution would be to translate these songs to something it can play when copying them to the ipod (and keep the original in itunes). All the tools to do this are available so it should just do this, no questions asked.


I’ve found some more serious issues with drag and drop:
9) You can drag albums to the sidebar to create a playlist and you can drag playlists to a folder but you cannot drag albums to folders to create a playlist there.

10) Dragging multiple albums sadly creates only one playlist so this is no solution for problem 2 and probably shares the same cause as problem 3.