Monday, October 23, 2006

Going to get milk, be right back.

I rant, therefore I am ... for those who know me or have met me in person, no explanation required.

I was ranting recently about some silly performance complaints and my victim (rantee ?) suggested I blog it instead of hammering him with my amusing "bon mots". I find ranting in person much more enjoyable but this time, for you readers, sure. If you want to read other rants or amusing techno sillyness, I recommend The Daily WTF which probably stands for "The Daily Weird Techno Fun" or something like that. Try this one or this one (for my close friends). Some funny stories there, that's for sure. But I digress.

So, here I am on the receiving end of some complaints about Java performance. Always keen to know more, I ask some questions. "What's slow ?, what are you trying to do ?" . Well, it turns out that they were 1) loading a class into its own class loader and 2) creating a single instance of it. Hmmm, this sounds suspicious, how could this be a performance problem ? Answer "we're doing it 100,000 times" ... ah yes, I see now. So, dig some more and find out the class is actually the same every time. OK. Step away from the keyboard, slowly, let me see your hands... ( I leave the recommendation as an exercise for the reader).

Listen, creating a classloader, loading a class, making one instance, and then throwing it all away is bad for performance, especially if you do it another 99,999 times. It's like renting a car, driving to the store for milk, returning the car and then coming to me to complain that "buying milk is too slow". Tip, keep the car for a while.

0 Comments:

Post a Comment

<< Home