Skip to content

[wip] Introduce CastType::Exact instead of reusing Prefix for exact casts - #3717

Closed
jswrenn wants to merge 5 commits into
G463fe47353c89d061e6458fa9c4bd19328a954a8from
G63f1cd381b283e8e5f75888830d802a40aa3507f
Closed

jswrenn wants to merge 5 commits into
G463fe47353c89d061e6458fa9c4bd19328a954a8from
G63f1cd381b283e8e5f75888830d802a40aa3507f

Conversation

@jswrenn

@jswrenn jswrenn commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Latest Update: v2 — Compare vs v1

📚 Full Patch History

Links show the diff between the row version and the column version.

Version v1 Base
v2 vs v1 vs Base
v1 vs Base
⬇️ Download this PR

Branch

git fetch origin refs/heads/G63f1cd381b283e8e5f75888830d802a40aa3507f && git checkout -b pr-G63f1cd381b283e8e5f75888830d802a40aa3507f FETCH_HEAD

Checkout

git fetch origin refs/heads/G63f1cd381b283e8e5f75888830d802a40aa3507f && git checkout FETCH_HEAD

Cherry Pick

git fetch origin refs/heads/G63f1cd381b283e8e5f75888830d802a40aa3507f && git cherry-pick FETCH_HEAD

Pull

git pull origin refs/heads/G63f1cd381b283e8e5f75888830d802a40aa3507f

Stacked PRs enabled by GHerrit.

gherrit-pr-id: Gfa0cb30780189c43bb84da57a9ade4d5a9754223
...so that they consume an `IntoBytes` as their source. Since these
methods are private, this does not yet increase expressivity for
users, but nonetheless allows the compiler to better optimize existing
callsites. For example, the `ref_from_prefix_dynamic_size` benchmark
becomes branchless, shrinking from 14 to 9 instructions. The falible
suffix-with-elems benchmarks shrink from 24 to 17 instructions for
dynamic size, and 28 to 20 instructions for dynamic padding. Only
`try_ref_from_prefix_dynamic_size` regresses, from 19 to 20 instructions.

gherrit-pr-id: Gd1b460a8ec2e8aa8adf2e070c329d9f209c7c89c
Refactors these routines to not depend on padding byte preservation
across moves. Along the way, we make the `try_read_from` helper safe,
generic, and better-optimized. Instruction counts for the
`try_read_from_*` change by -36% to -55%.

gherrit-pr-id: G35c8b8db33f4c984d5716af9a26c0a5ec9bd9c7e
This routine begins by rounding `bytes_len` down to the nearest multiple of
`align` (thus computing the intermediary `max_total_bytes`), subtracting the
offset of the trailing slice, and calculating how many elements (`elems`) fit in
that space. Then, in an expensive computation involving `elems`, the element
size, the trailing slice offset, `align`, the total `self_bytes` is computed.

This commit observes that when the element size is no larger than the `align`,
`self_bytes` is simply equal to `max_total_bytes`. For example, if
`max_total_bytes` is 16 bytes, the header occupies 9 bytes and two 3-byte
elements fit, they would occupy 15 bytes altogether, leaving 1 byte in excess.

This excess must be smaller than one element, otherwise another element would
fit. When `elem_size <= align`, the gap is smaller than `align` and trailing
padding fills it exactly.

gherrit-pr-id: G463fe47353c89d061e6458fa9c4bd19328a954a8
…ct casts

gherrit-pr-id: G63f1cd381b283e8e5f75888830d802a40aa3507f
@codecov-commenter

codecov-commenter commented Sep 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.90722% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.67%. Comparing base (cc5799d) to head (fe34cf4).

Files with missing lines Patch % Lines
zerocopy/src/lib.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@                              Coverage Diff                              @@
##           G463fe47353c89d061e6458fa9c4bd19328a954a8    #3717      +/-   ##
=============================================================================
- Coverage                                      92.68%   92.67%   -0.01%     
=============================================================================
  Files                                             20       20              
  Lines                                           6464     6542      +78     
=============================================================================
+ Hits                                            5991     6063      +72     
- Misses                                           473      479       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jswrenn

jswrenn commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator Author

I'm going to close this one for now until after we solve #3617.

@jswrenn jswrenn closed this Sep 25, 2026
@joshlf

joshlf commented Oct 5, 2026

Copy link
Copy Markdown
Member

#3617 is fixed

@joshlf joshlf reopened this Oct 5, 2026
@jswrenn
jswrenn force-pushed the G463fe47353c89d061e6458fa9c4bd19328a954a8 branch from cc5799d to 6f00605 Compare October 5, 2026 23:29
@jswrenn

jswrenn commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

Obsoleted (for now) by #3659.

@jswrenn jswrenn closed this Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants