Repository navigation
perf(parquet/file): avoid double bool bitmap conversion - #707
Merged
Merged
Conversation
Eliminates 8x memory overhead from bool[] conversion by writing directly from Arrow bitmap to Parquet bitmap. Changes: - Add AppendBitmap() to arrow/bitutil/BitmapWriter - Add PutBitmap() to PlainBooleanEncoder - Add DecodeToBitmap() to PlainBooleanDecoder - Add WriteBitmapBatch() methods to BooleanColumnChunkWriter - Integrate bitmap path in pqarrow encode_arrow.go Benefits: - Direct bit-level operations avoid 8x memory allocation - Eliminates redundant bitmap->[]bool->bitmap conversions - Maintains backward compatibility with existing []bool methods
added 2 commits
March 12, 2026 17:53
The bitmap optimization was failing for nullable columns because bitmap values at null positions are undefined/garbage. The old []bool path using Value(idx) properly handled nulls by consulting the validity bitmap. Fix: Only use direct bitmap path for non-nullable columns. Nullable columns fall back to []bool conversion to ensure correct null handling. This fixes test failures in TestSingleNullableListNullableColumnReadWrite.
Fixes staticcheck warning SA1019 in benchmark test.
zeroshade
force-pushed
the
perf/parquet-boolean-bitmap
branch
from
March 12, 2026 21:58
82df878 to
3b2e534
Compare
PR description will be provided in GitHub PR interface.
lidavidm
reviewed
Mar 13, 2026
lidavidm
left a comment
Member
There was a problem hiding this comment.
It might be good to unit-test the new methods?
Previously modified the generated file directly without updating the template. This commit adds the bitmap methods to the template so they persist across code regeneration. Changes to column_writer_types.gen.go.tmpl: - Add bitutil import - Add WriteBitmapBatch() for Boolean type - Add WriteBitmapBatchSpaced() for Boolean type - Add writeBitmapValues() helper for Boolean type - Add writeBitmapValuesSpaced() helper for Boolean type The generated file already contains these changes from previous commits.
- Fix AppendBitmap to properly flush and reload curByte - Add 8 test cases for AppendBitmap (aligned, unaligned, partial, etc.) - Add 2 encoder tests for PutBitmap (aligned and unaligned) - Add 2 decoder tests for DecodeToBitmap (aligned and unaligned) - Add 3 column writer tests for WriteBitmapBatch methods All tests pass successfully.
- Remove trailing whitespace - Fix slice expression spacing
Member
Author
|
@lidavidm unit tests added |
lidavidm
reviewed
Mar 14, 2026
Comment on lines
+433
to
+434
| // Note: Statistics and bloom filter updates would require converting back to []bool | ||
| // For now, skip them to maintain the performance benefit |
Member
There was a problem hiding this comment.
(Is there an issue filed for this?)
lidavidm
approved these changes
Mar 14, 2026
This was referenced Mar 16, 2026
zeroshade
added a commit
that referenced
this pull request
Mar 19, 2026
### Rationale for this change The initial bool optimization (#707) added direct bitmap encoding with `WriteBitmapBatch` and `WriteBitmapBatchSpaced` functions to reduce allocations during encoding and decoding. However, this didn't implement the same optimization for statistics updated, bloom filter inserts or spaced encoding. ### What changes are included in this PR? 1. Update the bloom filter handling to compute hashes directly from bitmaps, including for spaced values and reuse slice allocation across iterations. 2. Update statistics handling to update min/max directly from bitmaps for spaced and non-spaced scenarios. 3. Update the encoder interface for the boolean encoder to have a `PutSpacedBitmap` and compress bitmaps with validity buffers. 4. Add `writeBitmapValues` and `writeBitmapValuesSpaced` for the boolean column writer with fallback to `[]bool` conversions if the encoder doesn't implement the interface. ### Are these changes tested? Yes, unit tests are added for everything ### Are there any user-facing changes? No user-facing API changes, this is a pure internal optimization change for boolean columns. *Benchmark Results* *Statistics Update* ``` BEFORE (with bitmap → []bool conversion): BenchmarkBooleanStatisticsWithConversion-16 153,398 ns/op 109,278 B/op (107 KB) 6 allocs/op AFTER (direct bitmap operations): BenchmarkBooleanStatisticsDirectBitmap-16 393 ns/op 2,698 B/op (2.6 KB) 5 allocs/op ``` * 390x faster * 97.5% less memory * 1 fewer allocation *Bloom filter hashing* ``` BEFORE (with bitmap → []bool conversion): BenchmarkBloomFilterHashingWithConversion-16 1,084,001 ns/op 3,309,593 B/op (3.23 MB) 3 allocs/op AFTER (direct bitmap operations): BenchmarkBloomFilterHashingDirectBitmap-16 448,882 ns/op 802,821 B/op (784 KB) 2 allocs/op ``` * 2.4x faster * 76% less memory * 2.5 MB saved/operation * 1 fewer allocation *Full write path (Stats + Bloom Filter)* ``` BEFORE (with bitmap → []bool conversion): BenchmarkFullWritePathWithConversion-16 1,211,525 ns/op 3,315,566 B/op (3.24 MB) 15 allocs/op AFTER (direct bitmap operations): BenchmarkFullWritePathDirectBitmap-16 580,934 ns/op 807,640 B/op (789 KB) 13 allocs/op ``` * 2.1x faster * 76% less memory * 2.5 MB saved per 100k bools written * 2 fewer allocations --------- Co-authored-by: Matt <zero@gibson> Co-authored-by: Claude Sonnet 4.5 <[email protected]>
zeroshade
pushed a commit
that referenced
this pull request
Aug 18, 2026
## What does this PR do? - decodes Parquet BOOLEAN values directly into a packed bitmap - supports both PLAIN and RLE boolean pages - expands nullable values inside the bitmap without creating a `[]bool` - passes the record reader value bitmap directly to the Arrow Boolean array ## Why? The read path currently stores decoded booleans as one byte per value. It then allocates an Arrow bitmap and packs the values again in `transferBool`. This finishes wiring the direct bitmap decoder API from #707 into the pqarrow read path. The record reader now keeps boolean values packed from decoding through Arrow array construction. The change also fixes decoder state after a partial PLAIN bitmap decode, so the next call resumes at the correct source bit. ## Benchmarks Apple M1 Pro, 1M values, uncompressed Parquet, `GOMAXPROCS=1`: | case | before | after | change | before B/op | after B/op | change | | --- | ---: | ---: | ---: | ---: | ---: | ---: | | dense | 1.48 ms | 0.15 ms | -90% | 1.61 MB | 0.56 MB | -65% | | 50% null | 6.72 ms | 4.63 ms | -31% | 4.11 MB | 3.08 MB | -25% | ```text GOMAXPROCS=1 go test ./parquet/pqarrow -run '^$' -bench '^BenchmarkBooleanBitmapRead$' -benchmem -benchtime=500ms -count=5 ``` ## Tests - added direct bitmap tests for consecutive PLAIN decode calls - added nullable bitmap tests for PLAIN and RLE with unaligned offsets - ran `go test ./parquet/...` - ran race tests for the touched encoding, file, and pqarrow packages - ran `go vet` for the touched packages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Boolean columns currently get double converted when transferring between Arrow and Parquet
What changes are included in this PR?
1. Arrow bitutil (
arrow/bitutil/bitmaps.go)AppendBitmap()method toBitmapWriterCopyBitmap()2. Parquet encoder (
parquet/internal/encoding/boolean_encoder.go)PutBitmap()method toPlainBooleanEncoder3. Parquet decoder (
parquet/internal/encoding/boolean_decoder.go)DecodeToBitmap()method toPlainBooleanDecoder4. Column writer (
parquet/file/column_writer_types.gen.go)WriteBitmapBatch()for non-nullable boolean columnsWriteBitmapBatchSpaced()for nullable boolean columnswriteBitmapValues()andwriteBitmapValuesSpaced()5. Arrow-Parquet bridge (
parquet/pqarrow/encode_arrow.go)writeDenseArrow()to detect boolean arrays[]boolpath if needed (backward compatible)Are these changes tested?
Yes, and new benchmarks are added as appropriate
Are there any user-facing changes?
Just performance:
Non-Nullable Boolean Columns
Nullable Boolean Columns (10% null rate)
Key Observations:
[]boolconversion