GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Better use of bit manipulation instructions for bitmap iterations by richardstartin · Pull Request #227 · RoaringBitmap/RoaringBitmap Conversation
Member
I aim to speed container iteration up. Before doing that I did some instruction profiling, which revealed some suboptimal instructions were being JIT compiled for bitmap iteration: long t = bitset & -bitset; array[pos++] = (short) (base + Long.bitCount(t - 1)); bitset ^= t; 0.89% 0x0000000004b27296: blsi rbx,r10 0.93% 0x0000000004b2729b: mov rdi,rbx 2.22% 0x0000000004b2729e: xor rdi,r10 1.40% 0x0000000004b272a1: mov qword ptr [r11+10h],rdi 2.22% 0x0000000004b272a5: mov ecx,r8d 0.57% 0x0000000004b272a8: shl ecx,6h 2.06% 0x0000000004b272ab: dec rbx 1.24% 0x0000000004b272ae: popcnt rbx,rbx 2.25% 0x0000000004b272b3: add ecx,ebx Iterating over a bitmap of various densities looks like this:
This is very hotspot/Intel specific but C2 emits better code on Intel ("fusing" array[pos++] = (short) (base + numberOfTrailingZeros(bitset)); bitset &= (bitset - 1); 0.77% 0x0000000005605904: mov edi,r10d 1.60% 0x0000000005605907: shl edi,6h 3.19% 0x000000000560590a: tzcnt r8,r11 1.49% 0x000000000560590f: add edi,r8d 1.41% 0x0000000005605912: blsr r11,r11 This performs better:
Is this micro-optimisation? Yes. But if you have 5 dense bitmaps it would cost 100us. This only takes effect in code compiled by C2 and I don't know what the tradeoff is on different microarchitectures.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
|
Coverage decreased (-0.03%) to 91.058% when pulling b57a0e4 on richardstartin:use-blsr into 7d8b720 on RoaringBitmap:master. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I don't really get the coverage metrics reduction - this replaces three lines with two in several places. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Happy to merge this, but before we do... Are you interested in porting over the same changes to the buffer package? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Yes I will port them. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
There's not much justification for the changes in the buffer package. There may be a small benefit, and there is no cost, but I would be happy to revert the latest commit. My prejudice is that the inherent inefficiencies of |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
About coverage reduction, I guess you lowered the number of lines in a code very well covered. The weight of not-covered lines is then greater, hence decreasing the coverage ratio. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@BlasD have a gold star. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Minute coverage differences (-0.03%) are obviously not significant. Merging. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.