Cormac Blackwell

Greenhorn
+ Follow
since Oct 14, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Cormac Blackwell

Ok what the heck is the point of actual? What is the stream coming in as? Strings or byte arrays? Calling getBytes on a String is very slow and of course is creating new bytes arrays which will cause garbage collection.

Actually if equals against a string or toString is getting called you are allocating lots of objects for no apparent reason.

I would say you could be better of using Strings instead of Symbols and possibly interning the Strings

Object creation is almost free if the object is not held on too.

If the symbol is coming in as a byte array and it won't change while you are doing the lookup then you could use a much simpler wrapper

If you can't figure out your Java performance problems and go to C++ you are going to be well and truly boned.
18 years ago
Well you are creating a new char array in a loop and everytime you find a character you want to replace you are copying the whole string!
Try creating a single char array at the beginning which is twice the size you think you will need, then for each char either copy it or the replacement in (and resize the output array only if necessary and double the size if you have to resize it at all). Then you can contruct a string from the section of the array you have used. Also you probably should store the replacement strings as char arrays if you are just going to call toCharArray on them.

Actually I have a vague memory that toCharArray isn't that fast so you could be better off switching on string.charAt and appending to a single StringBuilder.
18 years ago
It was pretty simple



I had this inside an infinite loop so I could see any effects of jit compilation. Maybe the server VM is figuring out the results are always the same.
18 years ago
Resusing objects can be one of the worst things you can do for garbage collection times. Have a look at http://javaspecialists.co.za/archive/Issue115.html
You also could have a look at high performance collection libraries like trove or javolution.
18 years ago
A little while ago Larry Osterman (http://blogs.msdn.com/larryosterman/) wrote a post about optimisation tricks for counting the number of set bits in an int. I decided to try a few just out of curiosity of what java would do. the first one was the naive implementation:


This takes about 11 secs for 500,000,000 runs.

The most interesting result was with a lookup table based solution


This seemed to be horribly slow; around 34 secs for the same number of iterations.
But then I tried using the server VM. With that one the first 500,000,000 took around 12ms and from then on 0ms for the same number!!
So the client VM in this case is over 24,000 times slower!!!

Anyone have any idea what is going on?
18 years ago