Skip to content

[UIO] Explicit padding for numeric point - #8668

Merged
coszio merged 6 commits into
devfrom
padding-for-numeric-point
Apr 17, 2026
Merged

coszio merged 6 commits into
devfrom
padding-for-numeric-point

Conversation

@coszio

@coszio coszio commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

We need to derive bytemuck::Pod for Point<T>, but doing so for a generic requires it to be #[repr(C, packed)], which means we have to handle the padding ourselves.

This PR makes the padding part of the Numericable trait, and marks Point<T> as a Pod type. This enables it to be used in a TypedStorage<Point<T>>, which we need to migrate the mmap numeric index.

@coszio
coszio requested review from ffuugoo, generall and xzfc April 13, 2026 21:57

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs (1)

300-302: Consider explicit field ignoring for _padding.

Per coding guidelines, explicit field ignoring using : _ is preferred over .. in struct destructuring. However, since _padding is an internal implementation detail that will never affect logic, this is acceptable.

Optional: Explicit field ignoring
-            .map(|Point { val, idx, .. }| (val, idx))
+            .map(|Point { val, idx, _padding: _ }| (val, idx))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs` around
lines 300 - 302, The destructuring in the iterator mapping uses Point { val,
idx, .. } which relies on a blanket ignore; change it to explicitly ignore the
internal padding field by using Point { val, idx, _padding: _ } (or the exact
padding field name) in the closure so the intent is explicit; update the closure
in values_range_iterator(...).map(|Point { val, idx, .. }| (val, idx)) to use
the explicit ignored field name while returning (val, idx).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lib/segment/src/index/field_index/histogram.rs`:
- Around line 76-89: The derive_point_padding function can return align when the
summed size is already a multiple of align; change the logic to compute the
remainder rem = (size_of::<T>() + size_of::<PointOffsetType>()) % align and
return 0 if rem == 0 else return align - rem so derive_point_padding<T>() (which
defines struct Point<T>) yields zero padding when already aligned and only the
minimal positive padding otherwise.

---

Nitpick comments:
In `@lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs`:
- Around line 300-302: The destructuring in the iterator mapping uses Point {
val, idx, .. } which relies on a blanket ignore; change it to explicitly ignore
the internal padding field by using Point { val, idx, _padding: _ } (or the
exact padding field name) in the closure so the intent is explicit; update the
closure in values_range_iterator(...).map(|Point { val, idx, .. }| (val, idx))
to use the explicit ignored field name while returning (val, idx).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1a194799-83ea-4e75-8db1-7354b0ff091d

📥 Commits

Reviewing files that changed from the base of the PR and between 6115d76 and fb96459.

📒 Files selected for processing (6)
  • lib/segment/src/index/field_index/histogram.rs
  • lib/segment/src/index/field_index/numeric_index/immutable_numeric_index.rs
  • lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs
  • lib/segment/src/index/field_index/numeric_index/mutable_numeric_index.rs
  • lib/segment/src/index/field_index/tests/histogram_i64_tests.rs
  • lib/segment/src/index/field_index/tests/histogram_tests.rs

@generall

Copy link
Copy Markdown
Member

We need to derive bytemuck::Pod for Point

Why is it needed now?

we have to handle the padding ourselves.

What is padding in this case?

This enables it to be used in a TypedStorage<Point>

previos implementation used conversion from bytes?

@qdrant qdrant deleted a comment from coderabbitai Bot Apr 14, 2026
@coszio
coszio force-pushed the padding-for-numeric-point branch from fb96459 to e75f42b Compare April 14, 2026 14:11
coderabbitai[bot]

This comment was marked as resolved.

@coszio

coszio commented Apr 14, 2026

Copy link
Copy Markdown
Contributor Author

Why is it needed now?

Because, in #8641, we are going to be using it within TypedStorage, which requires this bound

What is padding in this case?

Padding is just [u8; N], where we calculate N based on whatever T is. Although, for concrete case, T is either f64 or i64. In theory it can also be u128, if we were to enable uuid range index.

previos implementation used conversion from bytes?

It was MmapSlice<Point<T>>

@coszio
coszio force-pushed the padding-for-numeric-point branch from e75f42b to 19e71fb Compare April 14, 2026 21:56
coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@qdrant qdrant deleted a comment from coderabbitai Bot Apr 16, 2026
coderabbitai[bot]

This comment was marked as resolved.

@coszio
coszio force-pushed the padding-for-numeric-point branch from 545d963 to e82459c Compare April 16, 2026 20:40
Comment thread shell.nix Resolved
@coszio
coszio force-pushed the padding-for-numeric-point branch from e82459c to 6063cb6 Compare April 16, 2026 21:38
@coszio
coszio force-pushed the padding-for-numeric-point branch from 6063cb6 to ba93027 Compare April 16, 2026 22:27
@coszio
coszio merged commit a9345a7 into dev Apr 17, 2026
15 checks passed
@coszio
coszio deleted the padding-for-numeric-point branch April 17, 2026 01:32
@qdrant qdrant deleted a comment from coderabbitai Bot Apr 17, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Apr 18, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Apr 27, 2026
8 of 9 tasks
timvisee pushed a commit that referenced this pull request May 8, 2026
* derive Pod for Point<T>

* remove clones on Copy type

* fix annoying clippy lint

* serde skip padding

* extract point into a new file

* assert aligment
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