[
https://issues.apache.org/jira/browse/HBASE-17233?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15722789#comment-15722789
]
ramkrishna.s.vasudevan commented on HBASE-17233:
------------------------------------------------
{code}
Benchmark Mode Cnt Score Error Units
ArrayCopy.arrayCopy thrpt 15 4269404.091 ± 392468.631 ops/s
ArrayCopy.copyRange thrpt 15 5184314.384 ± 577101.433 ops/s
{code}
What you said was right. But now my next doubt is what is that big difference
in Arrays.copyRange and System.arrayCopy?
{code}
@State(Scope.Thread)
public class ArrayCopy {
byte[] b = new byte[10000];
//byte[] res = new byte[10000];
byte[] res1 = new byte[10000];
@Setup
public void setup() {
}
@TearDown
public void teardown() {
}
@Benchmark
public void arrayCopy() {
arrayCopyInternal();
}
private void arrayCopyInternal() {
byte[] res = new byte[990];
System.arraycopy(b, 10, res, 0, 990);
return;
}
@Benchmark
public void copyRange() {
copyOfRangeInternal();
}
private void copyOfRangeInternal() {
byte[] copyOfRange = Arrays.copyOfRange(res1, 10, 1000);
return;
}
public static void main(String[] args) throws RunnerException {
Options opt = new
OptionsBuilder().include(ArrayCopy.class.getSimpleName()).warmupIterations(1)
.measurementIterations(2).forks(1).build();
new Runner(opt).run();
}
{code}
This is the new code.
> See if we should replace System.arrayCopy with Arrays.copyOfRange
> -----------------------------------------------------------------
>
> Key: HBASE-17233
> URL: https://issues.apache.org/jira/browse/HBASE-17233
> Project: HBase
> Issue Type: Improvement
> Affects Versions: 2.0.0
> Reporter: ramkrishna.s.vasudevan
> Assignee: ramkrishna.s.vasudevan
>
> Just saw this interesting comment in PB code. Since we deal with byte[]
> extensively (when we are onheap) we do lot of copies too.
> {code}
> * <p>One of the noticeable costs of copying a byte[] into a new array using
> * {@code System.arraycopy} is nullification of a new buffer before the
> copy. It has been shown
> * the Hotspot VM is capable to intrisicfy {@code Arrays.copyOfRange}
> operation to avoid this
> * expensive nullification and provide substantial performance gain.
> Unfortunately this does not
> * hold on Android runtimes and could make the copy slightly slower due to
> additional code in
> * the {@code Arrays.copyOfRange}.
> {code}
> So since we are hotspot VM we could see if the places we use System.arrayCopy
> can be replaced with Arrays.copyOfRange.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)