Skip to content

Preserve valid alignment when slicing buffer handles - #9647

Closed
danking wants to merge 1 commit into
developfrom
codex/primitive-slice-offset-alignment
Closed

Preserve valid alignment when slicing buffer handles#9647
danking wants to merge 1 commit into
developfrom
codex/primitive-slice-offset-alignment

Conversation

@danking

@danking danking commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Authored by Codex.

Summary

  • Add BufferHandle::slice_with_alignment, which reports the strongest alignment still guaranteed by a sliced view while enforcing a requested minimum alignment.
  • Use the new API when slicing primitive payload buffers so over-aligned buffers can be sliced at element-aligned offsets without preserving accidental allocation over-alignment.
  • Use the new API when extracting serialized buffers before the existing explicit ensure_aligned step.

Call-site assessment

  • PrimitiveArray slicing needed the fix; compressor sampling slices primitive arrays and was preserving 256-byte allocation alignment through f32 element-aligned views.
  • SerializedArray segment extraction now avoids strict source alignment before the explicit descriptor alignment check/copy.
  • Bool host slicing already uses unaligned byte slicing; the device path already relies on DeviceBuffer implementations to report view alignment.

Testing

  • cargo check -p vortex-array
  • cargo test -p vortex-array host_slice_reports_strongest_supported_view_alignment
  • cargo test -p vortex-array slice_over_aligned_f32_buffer_at_f32_aligned_offset
  • cargo test -p vortex-array slice

@codspeed-hq

codspeed-hq Bot commented Aug 26, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 12.3%

⚠️ 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

⚡ 1 improved benchmark
✅ 2129 untouched benchmarks
⏩ 106 skipped benchmarks1
🗄️ 4 archived benchmarks run2

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime multiply_shapes_neon[(128, PerRowPerRow)] 2.2 µs 2 µs +12.3%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing codex/primitive-slice-offset-alignment (49df2f7) with develop (7feec60)

Open in CodSpeed

Footnotes

  1. 106 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.

  2. 4 benchmarks were run, but are now archived. If they were deleted in another branch, consider rebasing to remove them from the report. Instead if they were added back, click here to restore them.

@0ax1
0ax1 requested review from 0ax1 and joseph-isaacs August 26, 2026 21:39
@danking
danking force-pushed the codex/primitive-slice-offset-alignment branch from beaf03d to 49df2f7 Compare August 26, 2026 21:47
@0ax1

0ax1 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

We have the notion of minimum and preferred alignment ( see buffer_mut.rs::with_capacity_aligned). The preferred alignment, our 256 bytes default, should only matter for allocation but never for correctness. There are no SIMD kernels that rely on and exploit the overalignment. Your PR patches the issue but the real issue is that we somewhere pass the preferred alignment as the required alignment. Saying slice_with_alignment should not be necessary.

@0ax1 0ax1 closed this Aug 27, 2026
@danking

danking commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants