Skip to content

Change ref_from_bytes() to inline(always).#3137

Merged
jswrenn merged 1 commit into
google:mainfrom
korran:inline-always
Mar 19, 2026
Merged

Change ref_from_bytes() to inline(always).#3137
jswrenn merged 1 commit into
google:mainfrom
korran:inline-always

Conversation

@korran

@korran korran commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

When building my firmware for rv32imc with lto=fat, changing codegen-units from 16 to 1 influences the compiler heuristics enough to not inline this function, causing code bloat and unnecessary panic logic.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@joshlf

joshlf commented Mar 18, 2026

Copy link
Copy Markdown
Member

You'll want to run ./tools/update-expected-test-output.sh to update expected output and fix the failing CI job.

@codecov-commenter

codecov-commenter commented Mar 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.87%. Comparing base (e38763f) to head (5a4f1e1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3137   +/-   ##
=======================================
  Coverage   91.87%   91.87%           
=======================================
  Files          20       20           
  Lines        6057     6057           
=======================================
  Hits         5565     5565           
  Misses        492      492           

☔ View full report in Codecov by Sentry.
📢 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.

When building my firmware for rv32imc with lto=fat, changing
codegen-units from 16 to 1 influences the compiler heuristics enough to
*not* inline this function, causing code bloat and unnecessary panic
logic.
@korran

korran commented Mar 18, 2026

Copy link
Copy Markdown
Contributor Author

hmm, those benchmark changes don't look good :(

@jswrenn jswrenn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The benchmark results are fine. :-) There's only a six instructions overhead on the dynamic padding case, and a hypothetical cycle improvement in the dynamic size case. Since dynamically padded types are unusual, not too much weight should be put in optimizing them relative to unpadded dynamically sized types.

@jswrenn jswrenn added this pull request to the merge queue Mar 19, 2026
Merged via the queue into google:main with commit d6d67bf Mar 19, 2026
108 checks passed
jswrenn added a commit that referenced this pull request Mar 19, 2026
Enables customers to tune inlining aggressiveness of many of zerocopy's
public functions. At higher `codegen-units`, the Rust compiler may fail
to inline invocations of conversion functions. Applying the
`#[inline(always)]` attribute (as in #3137) forces inlining, but that
might not be desirable for all monomorphizations or invocations.
Dynamically padded types, for instance, require much more complex
codegen than statically sized for unpadded dynamically sized types.

While reducing `codegen-units` for a build can improve codegen, it
carries a large penalty in build times. The `--cfg zerocopy_inline_always`
flag provides a narrowly-scoped lever for achieving some of the
benefits of `codegen-units=1` without the broad build time penalties.

gherrit-pr-id: G750518420a745aec19276f7a24bcd0f66584bb2c
jswrenn added a commit that referenced this pull request Mar 19, 2026
Enables customers to tune inlining aggressiveness of many of zerocopy's
public functions. At higher `codegen-units`, the Rust compiler may fail
to inline invocations of conversion functions. Applying the
`#[inline(always)]` attribute (as in #3137) forces inlining, but that
might not be desirable for all monomorphizations or invocations.
Dynamically padded types, for instance, require much more complex
codegen than statically sized for unpadded dynamically sized types.

While reducing `codegen-units` for a build can improve codegen, it
carries a large penalty in build times. The `--cfg zerocopy_inline_always`
flag provides a narrowly-scoped lever for achieving some of the
benefits of `codegen-units=1` without the broad build time penalties.

gherrit-pr-id: G750518420a745aec19276f7a24bcd0f66584bb2c
jswrenn added a commit that referenced this pull request Mar 19, 2026
Enables customers to tune inlining aggressiveness of many of zerocopy's
public functions. At higher `codegen-units`, the Rust compiler may fail
to inline invocations of conversion functions. Applying the
`#[inline(always)]` attribute (as in #3137) forces inlining, but that
might not be desirable for all monomorphizations or invocations.
Dynamically padded types, for instance, require much more complex
codegen than statically sized for unpadded dynamically sized types.

While reducing `codegen-units` for a build can improve codegen, it
carries a large penalty in build times. The `--cfg zerocopy_inline_always`
flag provides a narrowly-scoped lever for achieving some of the
benefits of `codegen-units=1` without the broad build time penalties.

gherrit-pr-id: G750518420a745aec19276f7a24bcd0f66584bb2c
jswrenn added a commit that referenced this pull request Mar 20, 2026
Enables customers to tune inlining aggressiveness of many of zerocopy's
public functions. At higher `codegen-units`, the Rust compiler may fail
to inline invocations of conversion functions. Applying the
`#[inline(always)]` attribute (as in #3137) forces inlining, but that
might not be desirable for all monomorphizations or invocations.
Dynamically padded types, for instance, require much more complex
codegen than statically sized for unpadded dynamically sized types.

While reducing `codegen-units` for a build can improve codegen, it
carries a large penalty in build times. The `--cfg zerocopy_inline_always`
flag provides a narrowly-scoped lever for achieving some of the
benefits of `codegen-units=1` without the broad build time penalties.

gherrit-pr-id: G750518420a745aec19276f7a24bcd0f66584bb2c
jswrenn added a commit that referenced this pull request Mar 20, 2026
Enables customers to tune inlining aggressiveness of many of zerocopy's
public functions. At higher `codegen-units`, the Rust compiler may fail
to inline invocations of conversion functions. Applying the
`#[inline(always)]` attribute (as in #3137) forces inlining, but that
might not be desirable for all monomorphizations or invocations.
Dynamically padded types, for instance, require much more complex
codegen than statically sized for unpadded dynamically sized types.

While reducing `codegen-units` for a build can improve codegen, it
carries a large penalty in build times. The `--cfg zerocopy_inline_always`
flag provides a narrowly-scoped lever for achieving some of the
benefits of `codegen-units=1` without the broad build time penalties.

gherrit-pr-id: G750518420a745aec19276f7a24bcd0f66584bb2c
jswrenn added a commit that referenced this pull request Mar 20, 2026
Enables customers to tune inlining aggressiveness of many of zerocopy's
public functions. At higher `codegen-units`, the Rust compiler may fail
to inline invocations of conversion functions. Applying the
`#[inline(always)]` attribute (as in #3137) forces inlining, but that
might not be desirable for all monomorphizations or invocations.
Dynamically padded types, for instance, require much more complex
codegen than statically sized for unpadded dynamically sized types.

While reducing `codegen-units` for a build can improve codegen, it
carries a large penalty in build times. The `--cfg zerocopy_inline_always`
flag provides a narrowly-scoped lever for achieving some of the
benefits of `codegen-units=1` without the broad build time penalties.

gherrit-pr-id: G750518420a745aec19276f7a24bcd0f66584bb2c
github-merge-queue Bot pushed a commit that referenced this pull request Mar 20, 2026
Enables customers to tune inlining aggressiveness of many of zerocopy's
public functions. At higher `codegen-units`, the Rust compiler may fail
to inline invocations of conversion functions. Applying the
`#[inline(always)]` attribute (as in #3137) forces inlining, but that
might not be desirable for all monomorphizations or invocations.
Dynamically padded types, for instance, require much more complex
codegen than statically sized for unpadded dynamically sized types.

While reducing `codegen-units` for a build can improve codegen, it
carries a large penalty in build times. The `--cfg zerocopy_inline_always`
flag provides a narrowly-scoped lever for achieving some of the
benefits of `codegen-units=1` without the broad build time penalties.

gherrit-pr-id: G750518420a745aec19276f7a24bcd0f66584bb2c
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.

4 participants