StringBuffer / StringBuilder performance improvements

Lately I've been thinking about some (possible) performance improvements for StringBuffer / StringBuilder:

Now, SBs are designed to work with char-arrays, because they are mutable, and if you append a value, you don't need to create extra objects. In most use-cases, an SB will be used to concatenate some (String)values. Most people don't set the initialCapacity, because that requires some extra code. The default cap is 16. Now, let's concat some strings:

sb.append("Hello ").append("Joris"/*user.getName()*/).append(", how are you doing ").append("Today?" /* or night */);

This will do the following:

check capacity for 6 more chars
copy "Hello " chars
count = 6

check capacity for 5 more chars
copy "Hello " chars
count = 11

check capacity for 18 more chars
expand capacity: curcap*2 or newsize -> (16+1)*2 > 5+9 --> newcap = 34
copy "Hello Joris"
copy " how are you doing " chars
count = 29

check capacity for 6 more chars
expand capacity: curcap*2 or newsize -> (16+1)*2 > 34+6 --> newcap = 70
copy "Hello Joris how are you doing "
copy "Today?" chars
count = 6


Ok.. So.. how could we prevent the expanding? If we'd have set the initialCapacity to 40, that wouldn't have happened. But as I said, nobody really does that, except for high performance stuff.

If you create an SB that will keep an linked list (or arraylist and probably a custom implementation) of strings and just add the new strings to the list. You wouldn't have to do all the copying. Only when you invoke toString() (or charAt, or something similar), you will have to create a single string. But by then, you already know how large the string will be!

That way, you prevent temporary array copies, temporary char-array creations and destructions, and therefore reducing GC.

Of course, I haven't tested all this in a real life situation :) If someone has a nice testcase for String concatenation performance, please send it to me. The tests I do are biased ofcourse ^^.

Share this:

Firefox 3 beta 1: slow resizing, and no google toolbar

Well, today I installed Firefox3 . First impressions: it seems faster, but we'll see if the memory leaks / hanging threads / 100% cpu bugs are fixed :)... I don't think they are, because they'd have fixed them in FF2 by now then. One thing I really am missing is the Google Toolbar. I got used to it. I like the gmail / rss notifiers, quickfind and the US-search button. My default google search is Dutch, but sometimes I just check if I can find the things I'm looking for with the US-engine.

I get the folowing error:
Google Toolbar for Firefox 3.0.20070525W could not be installed because it is not compatible with Firefox 3.0b1


2 weeks ago I tried FF3 too, and somewhere I saw that firefox was reporting version 0.0.0, but I can't remember where I saw that :(

Share this:

How not to run a delivery company

Ok, so I ordered a new workstation yesterday, a quadcore 6600 + 4gb ram + 500gb hdd. I chose pay at the door, because transferring from bank to bank takes 2 or 3 days (insane...) and I wanted it here so I could install and test it over the weekend.

The TNT Post guy came at my house and told me:
I could NOT use my atm card. I had to pay cash.
I could NOT go to the atm machine (600 meters from here) to get some cash
I could NOT go after him and pay him (his next few packages were also in the street)
He could NOT go back to my house after his other packages
He could NOT leave the package at the post office, because he HAD to deliver it twice first.

If I order a pizza from Domino's or whatever, I can pay the few euro's by ATM on the spot or pay in advance using iDeal (out Dutch internet payment system)

So basically I'm pissed off right now, because I can't play with my new toy. + I payed extra to get the package here in a day.

Thank you TNT Post, I know I'll be using other companies when in the future I have to send something..

Share this:

No postgresql for symmetricds

It looks like I hadn't read enough about symds. There's no postgresql dialect yet, but I'm thinking of writing one for them. It shouldn't be too much work, and I really need it :) I'll keep y'all posted.

Share this:

Wow.. almost a month ago since my last post! I've been spending some time with my gf, working on a project, and on Armada. We've setup the forums at forum.bloomsix.com so feel free to register :D

I just read about symmetricds.org, and it seems like it does what I want. Basically I have 2 workstations (1 desktop, 1 laptop), and a server (for production and development). Now, maintaining those databases are a pain in the ass IMHO, and I was looking for replication for data and schemas for mysql and postgresql. The problem is, there isn't a good solution yet for this.. I found something for pgsql, but that was linux only, and my workstations are winxp. I hate cygwin, and I hate compiling :)

Tomorrow I'll try to setup replication, and if all goes well, I'll have a cool development database that I can use accross my machines and even without network connection!

Share this: