Skip to content

fix(buffer): don't create &mut [u64] over uninitialized memory in collect_words_in - #10294

Open
jianhe25 wants to merge 1 commit into
vortex-data:developfrom
jianhe25:buffer-fix-5
Open

jianhe25 wants to merge 1 commit into
vortex-data:developfrom
jianhe25:buffer-fix-5

Conversation

@jianhe25

@jianhe25 jianhe25 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

BitBufferMut::collect_words_in allocated with with_capacity_in, called set_len to claim the memory was initialised, and passed as_mut_slice() to the fill closure. That creates a &mut [u64] over uninitialised memory before anything writes to it. The safety comment argued this was fine because fill writes every word and u64 has no invalid bit patterns, but a reference to uninitialised memory is UB on its own.

This uses BufferMut::zeroed_in(num_words, allocator) instead, keeping the allocator. fill still overwrites every word, so the only extra cost is one memset.

Testing

  • Behaviour is unchanged and already covered by the existing BitBufferMut tests; I didn't add a new one.
  • cargo test -p vortex-buffer --all-features, clippy, nightly fmt, and Miri on bit::buf_mut with CI's MIRIFLAGS.

AI assistance

This change was prepared with help from an AI coding assistant (Google-internal agentic tooling). I reviewed and verified the change and the tests myself.

`BitBufferMut::collect_words_in` allocated with `with_capacity`, immediately called
`set_len` to claim the memory was initialised, and then handed `as_mut_slice()` to the
fill closure. That materialises a `&mut [u64]` over uninitialised memory before anything
has written to it.

The existing safety comment argued this was acceptable because `fill` writes every word
and `u64` has no invalid bit patterns. That is not sufficient: producing a reference to
uninitialised memory is Undefined Behaviour in its own right, independent of the validity
invariants of the referent type.

Use `BufferMut::zeroed`, which returns an allocation whose elements are already
initialised and whose length is already set. `fill` still overwrites every word, so the
only cost is one memset.

Signed-off-by: Jian He <hejia@google.com>
@robert3005 robert3005 added the changelog/fix A bug fix label Oct 5, 2026
@robert3005
robert3005 enabled auto-merge (squash) October 5, 2026 10:19
@robert3005
robert3005 disabled auto-merge October 5, 2026 10:19
@robert3005 robert3005 added the action/bench-sql Run SQL benchmarks without Vortex Compact on this PR label Oct 5, 2026
@codspeed

codspeed Bot commented Oct 5, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 17.24%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 2 regressed benchmarks
✅ 2101 untouched benchmarks
⏩ 503 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation from_bool_slice[65536] 74.6 µs 97.4 µs -23.46%
❌ WallTime dict_canonicalize_gt_u8_avx512[1000000] 422.3 µs 472 µs -10.52%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing jianhe25:buffer-fix-5 (0f4e9c6) with develop (b127616)

Open in CodSpeed

Footnotes

  1. 503 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action/bench-sql Run SQL benchmarks without Vortex Compact on this PR changelog/fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants