zeroshade opened a new pull request, #1552:
URL: https://github.com/apache/arrow-go/pull/1552
### Rationale for this change
Decoding an ALP vector makes four passes over its values, and copies the
packed bytes once before the first:
- `BitReader.GetBatch` unpacks the deltas. The vectorized unpackers behind
it read through an `io.Reader`, so the packed bytes are copied into a pooled
buffer first, and the unpacked `uint32`s are then widened to `uint64`.
- A loop generic over the float type adds the frame of reference to each
delta and scales it into the decoder's buffer.
- The exceptions are patched in through a generic helper that looks the type
up for every value.
- The values are copied to the caller.
Deltas wider than 32 bits never reach the vectorized unpackers: `GetBatch`
reads them one value at a time.
### What changes are included in this PR?
- `utils.Unpack32Vectorized` runs the NEON or AVX2 unpacker on a byte slice
directly. It unpacks nothing on a platform without one.
- Deltas of up to 32 bits are unpacked with it straight from the page, and
scaled in a second pass written for each type. Wider deltas, and every delta on
a platform without a vectorized unpacker, are unpacked and scaled in one pass,
with one 8-byte load per delta.
- A read that starts at a vector and covers all of it is decoded into the
caller's slice rather than the decoder's buffer.
- Exceptions are patched by a loop written for each type.
- A vector of zero bit width is filled with its one value.
The unpacking loops load a few bytes past a vector's packed deltas. Those
bytes are the vector's exceptions or the next vector. Only the last vector of a
page can be without them, and it is unpacked from a padded copy.
Timings on an Apple M4 (darwin/arm64). The machine was busy with other work,
so `main` and this branch were run in alternating short turns, 50 samples each.
The spread is wide, and the absolute times are slower than on an idle machine,
but both sides ran under the same conditions:
```
│ main │
PR │
│ sec/op │ sec/op
vs base │
ALPDecodingFloat32/no_exceptions/len_1024-10 1258.0n ± 12% 599.8n ±
10% -52.32% (p=0.000 n=50)
ALPDecodingFloat32/no_exceptions/len_65536-10 84.73µ ± 16% 35.62µ ±
17% -57.96% (p=0.000 n=50)
ALPDecodingFloat32/10%_exceptions/len_1024-10 1607.0n ± 11% 593.0n ±
14% -63.10% (n=50)
ALPDecodingFloat32/10%_exceptions/len_65536-10 111.59µ ± 6% 40.05µ ±
11% -64.12% (p=0.000 n=50)
ALPDecodingFloat32/all_exceptions/len_1024-10 4287.0n ± 15% 809.5n ±
12% -81.12% (p=0.000 n=50)
ALPDecodingFloat32/all_exceptions/len_65536-10 260.66µ ± 13% 51.08µ ±
14% -80.40% (p=0.000 n=50)
ALPDecodingFloat64/no_exceptions/len_1024-10 1335.5n ± 13% 591.8n ±
16% -55.69% (p=0.000 n=50)
ALPDecodingFloat64/no_exceptions/len_65536-10 93.38µ ± 9% 36.95µ ±
10% -60.43% (p=0.000 n=50)
ALPDecodingFloat64/10%_exceptions/len_1024-10 1741.5n ± 8% 651.2n ±
17% -62.61% (n=50)
ALPDecodingFloat64/10%_exceptions/len_65536-10 103.73µ ± 13% 42.27µ ±
15% -59.25% (p=0.000 n=50)
ALPDecodingFloat64/all_exceptions/len_1024-10 4158.5n ± 14% 736.5n ±
12% -82.29% (n=50)
ALPDecodingFloat64/all_exceptions/len_65536-10 255.89µ ± 21% 52.04µ ±
14% -79.66% (p=0.000 n=50)
ALPDecodingFloat64Batched/len_1024-10 1732.5n ± 16% 857.5n ±
13% -50.50% (p=0.000 n=50)
ALPDecodingFloat64Batched/len_65536-10 109.50µ ± 13% 55.60µ ±
13% -49.23% (p=0.000 n=50)
ALPDecodingFloat64Wide/len_1024-10 8.127µ ± 15% 1.096µ ±
8% -86.51% (n=50)
ALPDecodingFloat64Wide/len_65536-10 519.79µ ± 9% 63.99µ ±
10% -87.69% (p=0.000 n=50)
geomean 19.42µ 5.795µ
-70.16%
```
`Wide` is a benchmark this PR adds, for deltas of about 50 bits. I have no
amd64 timings: the AVX2 path is covered by the tests, not by a benchmark run.
### Are these changes tested?
Yes, by new tests of the loops and of the decoder, and by the existing ALP
tests.
### Are there any user-facing changes?
No.
--
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]