zeroshade commented on code in PR #14442:
URL: https://github.com/apache/arrow/pull/14442#discussion_r1000805696
##########
go/arrow/bitutil/bitmaps.go:
##########
@@ -390,15 +396,26 @@ func CopyBitmap(src []byte, srcOffset, length int, dst
[]byte, dstOffset int) {
rdr := NewBitmapWordReader(src, srcOffset, length)
wr := NewBitmapWordWriter(dst, dstOffset, length)
+ var modify func(in uint64) uint64
+ switch mode {
+ case transferCopy:
+ modify = func(in uint64) uint64 { return in }
+ case transferInvert:
+ modify = func(in uint64) uint64 { return ^in }
+ }
+
nwords := rdr.Words()
for nwords > 0 {
nwords--
- wr.PutNextWord(rdr.NextWord())
+ wr.PutNextWord(modify(rdr.NextWord()))
Review Comment:
I did a comparison on the benchmarks and it looks like you're right (looking
a bit further into the Go opimization, I don't believe they yet fully inline
functions line the `modify` case here).
I got this from the benchmarks where `old speed` is the version using an
`if` and `new speed` is using the `modify` anonymous function approach here:
```
name old speed new speed delta
CopyBitmapWithOffset/32-20 202MB/s ± 5% 201MB/s ± 4% ~
(p=0.678 n=20+20)
CopyBitmapWithOffset/128-20 566MB/s ± 3% 555MB/s ± 7% -2.07%
(p=0.033 n=20+20)
CopyBitmapWithOffset/1000-20 1.29GB/s ± 4% 1.23GB/s ± 3% -4.94%
(p=0.000 n=20+19)
CopyBitmapWithOffset/1024-20 1.31GB/s ± 3% 1.23GB/s ± 5% -6.52%
(p=0.000 n=20+20)
CopyBitmapWithOffsetBoth/32-20 174MB/s ± 3% 176MB/s ± 3% +1.19%
(p=0.028 n=20+19)
CopyBitmapWithOffsetBoth/128-20 443MB/s ± 2% 442MB/s ± 3% ~
(p=0.723 n=17+20)
CopyBitmapWithOffsetBoth/1000-20 832MB/s ± 3% 823MB/s ± 3% ~
(p=0.072 n=20+18)
CopyBitmapWithOffsetBoth/1024-20 844MB/s ± 3% 829MB/s ± 3% -1.73%
(p=0.001 n=20+20)
```
Only one case shows the function as a better option, and that's within the
margin of error, so i'll change this to being an `if` and call it a day :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]