David Daney wrote:
Ian Rogers wrote:
Hi,

please give your comments on the attached patch. It tries to reduce the size of char[] for strings used to hold numbers. It changes Float/Double equals to use bit based comparisons rather than division. It increases the use of valueOf methods. It adds a cache of values from -128 to 127 for Long. It adds a cache of the values of zero and one to Float and Double.

The string size is an estimate. For decimal numbers it will divide the value repeatedly by 8, causing the string length to be over estimated by a character for values like 999. This string size is still better than the current estimate of 33 characters. It also avoids the use of division (shifts are used) and/or lookup tables.


I would like to know your motivation for doing this. Do you have any evidence that this will reduce memory usage and speed up real applications?


That said, in our gcj-3.4 based application, we had to create a cache of Integers because we were creating large numbers of them all with a small set of values.

So in principle this could be a good approach, but I don't know if we can assume that there is universal benefit from a patch like this. Can you point to any benchmarks where this helps?


Thanks,
David Daney
Hi David,

I'm having a crack down on wasted memory in the Jikes RVM.

For DaCapo fop (single iteration) there are 270 and 977 occurrences of Double 0 and 1 and 20 occurrences of other Doubles. On the other hand DaCapo bloat has very few 0 and 1 values. My motivation to cache these, other than fop, is that they exist as bytecodes (fconst0/fconst1 and dconst0/dconst1, although I'm ignoring fconst2 and dconst2). We already cache Integers in the intCache. I do extend this concept to Long, as is done in OpenJDK, and to Float and Double.

Currently we always allocated 33 char arrays to hold the string value, this is 4.625 the size of the minimum object in the RVM. In the case of a single character string, 18.86% of Integer strings in DaCapo bloat, this code doesn't allocate any char arrays. For other integers the char array is reduced to either the exact or (20% of the time for decimal values) 1 character longer char arrays. This is at the cost of up to 32 compares, branches and shifts. For DaCapo bloat a little under 50% of integer strings created are for values between -128 and 127.

So the trade offs in the code are, slower Float/Double valueOf code, but fewer Float and Double objects (hopefully improving GC). A small time to calculate string sizes vs smaller strings and less GC pressure.

For the Jikes RVM we measure performance 4 times a day [1], I introduced this patch in r14113 and there are no peaks or troughs that appear at this point. Given the patch is performance neutral but saves memory (although not improving GC performance for the RVM markedly) I think it's worth including. GC is less than 6% of execution time, so time saved may be difficult to measure in the bigger picture (unless it pushes you under or over a particular threshold).

Regards,
Ian

[1] http://jikesrvm.anu.edu.au/cattrack/results/rvmx86lnx32.anu.edu.au/perf/3437/performance_report

Reply via email to