Issue Details (XML | Word | Printable)

Key: HARMONY-6056
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Tim Ellison
Reporter: Kevin Zhou
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Harmony

[classlib][jit][opt][performance] Optimize heap allocations in String(String, int) constructor for JIT

Created: 22/Dec/08 03:07 AM   Updated: 13/Jan/09 07:30 PM
Return to search
Component/s: Classlib
Affects Version/s: 5.0M8
Fix Version/s: 5.0M9

Time Tracking:
Original Estimate: 24h
Original Estimate - 24h
Remaining Estimate: 24h
Remaining Estimate - 24h
Time Spent: Not Specified
Remaining Estimate - 24h

File Attachments:
  Size
File Licensed for inclusion in ASF works HARMONY-6056.diff 2008-12-22 03:31 AM Kevin Zhou 2 kB
Java Archive File Licensed for inclusion in ASF works StringBench.jar 2009-01-07 10:52 PM Aleksey Shipilev 8 kB
Java Archive File Licensed for inclusion in ASF works StringBench.jar 2009-01-07 10:43 PM Aleksey Shipilev 8 kB
Issue Links:
Reference
 

Estimated Complexity: Moderate
Resolution Date: 13/Jan/09 06:18 AM


 Description  « Hide
This patch optimizes heap allocations in String(String, int) constructor for JIT performance improvement.


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Kevin Zhou added a comment - 22/Dec/08 03:31 AM
Would you please help to try it?

Kevin Zhou made changes - 22/Dec/08 03:31 AM
Field Original Value New Value
Attachment HARMONY-6056.diff [ 12396577 ]
Nathan Beyer added a comment - 22/Dec/08 03:59 AM
Can you provide some context and background to this patch? Thanks

Kevin Zhou added a comment - 22/Dec/08 04:12 AM
The private String(String, int) constructor is too heavy in its current implementation as it uses String.valueOf(int), which in turn uses Integer.toString(int), which contains two heap allocations inside. Apparently, if we use division to convert an integer to string can be much faster.
In addition, the changes on String.indexOf method can improve SPECjbb2005 score.

Kevin Zhou added a comment - 22/Dec/08 04:13 AM
I hope that this would be valid for you

Aleksey Shipilev added a comment - 22/Dec/08 08:39 AM
Kevin, why not to patch Integer.toString(int) instead?

Kevin Zhou added a comment - 23/Dec/08 02:21 AM
Integer.toString(int) contains two heap allocations inside which may be much slower than dividing and converting an integer to string.

Tim Ellison made changes - 06/Jan/09 01:13 PM
Assignee Tim Ellison [ tellison ]
Tim Ellison added a comment - 06/Jan/09 01:13 PM
Aleksey: are you ok with this patch?

Aleksey Shipilev added a comment - 06/Jan/09 03:00 PM
Had a annual memory reset during NY :)

I agree with Kevin's rationale. Are you sure that the performance boost is about heap allocation? The code in the patch and Integer.toString(int) look different.

On the other hand, if the added code in String(String, int) is inlined Integer.toString(int), this is a code duplication. My first thought was: to avoid that, can we just make package-private Integer.toString(char[], int, int), where we can put the target array, offset and the value? Then in String(String, int) we may just call that method. And finally, we can reduce the code duplication by calling the same method from Integer.toString() :)

It would also testify the performance boost is related to heap allocation, not the changed conversion implementation.
If the boost is connected with specialized conversion for radix 10, then it's rather better to specialize it at Integer, rather than at String :)

Does that makes sense?

Aleksey Shipilev added a comment - 06/Jan/09 06:57 PM
Just flashed into my mind.
Kevin, what javac/JVM you use to make the performance runs? Is it J9 or DRLVM? Are there any steps to reproduce the result?

AFAIK, DRLVM does not substitute the "String s2 = (String)s1 + (int)v1;" to "new String(s1, v1)", is it J9 who does this thing? If so the another benefit of generalizing your solution in Integer.toString(), because DRLVM can then tap on your probably-optimized radix-10 conversion when concatenating strings via StringBuilder.

Aleksey Shipilev added a comment - 07/Jan/09 10:43 PM
StringBench.jar

Simple benchmark to evaluate "(String)base + (int)add" operation performance. I presume that the attached patch should increase the score on this benchmark.

On Harmony-M7 at P-D 2.8 Ghz / PC2-5300 / Gentoo Linux x86:

$ harmony-M7/bin/ava -Xms1024M -Xmx1024M -server -jar StringBench.jar
(String)base + (int)add:
-------------------------------------------
 base length (vars with rows): 0..2..10
  add length (vars with cols): 0..2..10

 loop duration = 100 msecs
 target variance = 0.05

ops/msec, the more the better:
4369, 2842, 1976, 1563, 1226,
4462, 2829, 1966, 1555, 1225,
4430, 2836, 1956, 1563, 1223,
4394, 2831, 1956, 1558, 1217,
4357, 2821, 1954, 1551, 1217,

Aleksey Shipilev made changes - 07/Jan/09 10:43 PM
Attachment StringBench.jar [ 12397340 ]
Aleksey Shipilev made changes - 07/Jan/09 10:52 PM
Attachment StringBench.jar [ 12397342 ]
Aleksey Shipilev made changes - 08/Jan/09 10:58 AM
Link This issue relates to HARMONY-6068 [ HARMONY-6068 ]
Tim Ellison added a comment - 09/Jan/09 10:09 AM
Do we agree to close this now?

Kevin Zhou added a comment - 13/Jan/09 06:18 AM
Merge with HARMONY-6068. This can be closed now.

Kevin Zhou made changes - 13/Jan/09 06:18 AM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Aleksey Shipilev added a comment - 13/Jan/09 07:30 PM
Just wondering: is the boost from HARMONY-6068 equals to this patch, while running on J9?
Where did it come from finally: reduced heap allocation or optimized conversion?