[ 
https://issues.apache.org/jira/browse/GEODE-6579?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16812888#comment-16812888
 ] 

Darrel Schneider commented on GEODE-6579:
-----------------------------------------

I added a thread local byte array cache and ran a jmh benchmark to see how it 
compared to just creating a new byte array each time.

The thread local cache was ~20% faster in this micro-benchmark. The following 
show the readString calls/ms for different length strings. The benchmark 
preserialized the data so the only thing measured in it was the actual 
deserialization of the string.
||length||old||new||diff||
|35|18237|22278|+18%|
|70|13778|17062|+20%|
|140|8759|10931|+20%|
|280|4466|5962|+25%|
|560|2101|2712|+23%|
|1120|1144|1411|+18%|

> Creating a String during deserialization could be optimized
> -----------------------------------------------------------
>
>                 Key: GEODE-6579
>                 URL: https://issues.apache.org/jira/browse/GEODE-6579
>             Project: Geode
>          Issue Type: Improvement
>          Components: serialization
>            Reporter: Darrel Schneider
>            Assignee: Darrel Schneider
>            Priority: Major
>              Labels: optimization
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> When creating a string during deserialization from data that we know is in 
> the ASCII character set (each character can be represented by one byte) we 
> currently read all the bytes into a temporary byte array and then create a 
> String instance by giving it that byte array. The String constructor has to 
> create its own char array and then copy all the bytes into it. After that the 
> byte array is garbage.
> We could instead directly create a char array, fill it by reading each byte 
> from the DataInput into it and then using reflection to directly set this 
> char array as the value field of the String instance we just created (as an 
> empty String). This prevents an extra copy of the data and reduces garbage 
> creation.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to