Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Tuid #8999

Merged
merged 9 commits into from
Feb 12, 2025
Merged

Improve Tuid #8999

merged 9 commits into from
Feb 12, 2025

Conversation

emilk
Copy link
Member

@emilk emilk commented Feb 11, 2025

Related

What

Improve re_tuid::Tuid, and by extension RowId and ChunkId (which are just typesafe wrappers around Tuid)

Details

  • Implement from_str for Tuid/RowId/ChunkId
  • Slightly modify how Tuid is formatted as a string (in backwards/forwards compatible way!)]
  • Implement bytemucking
  • Align to bytes (see below)

Change Tuid alignment from 8 to 1

This will allow us to cast raw bytes into a &[RowId].

arrow-rs already aligns all allocations to 64 bytes, so theoretically there would be nothing to stop us from already doing this, but this is the "better safe than sorry" approach.

uuid:::Uuuid is also aligned to bytes, FWIW.

  • Tuid::new becomes ~7% slower
  • Tuid::cmp is unaffected

@emilk emilk added 🚜 refactor Change the code, not the functionality exclude from changelog PRs with this won't show up in CHANGELOG.md labels Feb 11, 2025
Copy link

github-actions bot commented Feb 11, 2025

Web viewer built successfully. If applicable, you should also test it:

  • I have tested the web viewer
Result Commit Link Manifest
bbaa70a https://rerun.io/viewer/pr/8999 +nightly +main

Note: This comment is updated whenever you push a commit.

@emilk emilk force-pushed the emilk/tuid-improvements branch from bb32ec0 to f806716 Compare February 11, 2025 20:36
@emilk emilk force-pushed the emilk/tuid-improvements branch from f806716 to 83ee7c6 Compare February 11, 2025 20:50
@teh-cmc teh-cmc self-requested a review February 12, 2025 08:13
Copy link
Member

@teh-cmc teh-cmc left a comment

Choose a reason for hiding this comment

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

I like it, except for the string representation shenanigans.

crates/utils/re_tuid/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +299 to +301
fn test_tuid_size_and_alignment() {
assert_eq!(std::mem::size_of::<Tuid>(), 16);
assert_eq!(std::mem::align_of::<Tuid>(), 1);
Copy link
Member

Choose a reason for hiding this comment

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

Can we use static_assertions for these things these days?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can, but it adds a dependency for no gain?

Copy link
Member

@teh-cmc teh-cmc Feb 12, 2025

Choose a reason for hiding this comment

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

It makes the type self-documenting in ways that comments or freestanding tests never will, and static_assertions is already an indirect dep of re_tuid.

/// The format uses upper case for the first 16 hex digits, and lower case for the last 16 hex digits.
/// This is to make it easily distinguished from other hex strings.
///
/// Example: `182342300C5F8C327a7b4a6e5a379ac4`
Copy link
Member

Choose a reason for hiding this comment

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

Eeeeeeeh, this part I'm really not a fan tbh, but okay 🤷

Co-authored-by: Clement Rey <[email protected]>
@emilk emilk merged commit a4d3725 into main Feb 12, 2025
35 checks passed
@emilk emilk deleted the emilk/tuid-improvements branch February 12, 2025 09:28
@emilk emilk mentioned this pull request Feb 12, 2025
emilk added a commit that referenced this pull request Feb 12, 2025
jprochazk pushed a commit that referenced this pull request Feb 13, 2025
### Related
* Part of #8992

### What
Improve `re_tuid::Tuid`, and by extension `RowId` and `ChunkId` (which
are just typesafe wrappers around `Tuid`)

### Details
* Implement `from_str` for `Tuid/RowId/ChunkId`
* Slightly modify how Tuid is formatted as a string (in
backwards/forwards compatible way!)]
* Implement bytemucking
* Align to bytes (see below)

### Change `Tuid` alignment from `8` to `1`
This will allow us to cast raw bytes into a `&[RowId]`.

`arrow-rs` already aligns all allocations to 64 bytes, so
_theoretically_ there would be nothing to stop us from already doing
this, but this is the "better safe than sorry" approach.

`uuid:::Uuuid` is also aligned to bytes, FWIW.

* `Tuid::new` becomes ~7% slower
* `Tuid::cmp` is unaffected

---------

Co-authored-by: Clement Rey <[email protected]>
jprochazk pushed a commit that referenced this pull request Feb 13, 2025
### Related
* Part of #8992

### What
Improve `re_tuid::Tuid`, and by extension `RowId` and `ChunkId` (which
are just typesafe wrappers around `Tuid`)

### Details
* Implement `from_str` for `Tuid/RowId/ChunkId`
* Slightly modify how Tuid is formatted as a string (in
backwards/forwards compatible way!)]
* Implement bytemucking
* Align to bytes (see below)

### Change `Tuid` alignment from `8` to `1`
This will allow us to cast raw bytes into a `&[RowId]`.

`arrow-rs` already aligns all allocations to 64 bytes, so
_theoretically_ there would be nothing to stop us from already doing
this, but this is the "better safe than sorry" approach.

`uuid:::Uuuid` is also aligned to bytes, FWIW.

* `Tuid::new` becomes ~7% slower
* `Tuid::cmp` is unaffected

---------

Co-authored-by: Clement Rey <[email protected]>
jprochazk pushed a commit that referenced this pull request Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exclude from changelog PRs with this won't show up in CHANGELOG.md 🚜 refactor Change the code, not the functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants