Skip to content

optimize: use inline hint instead of inline(always) for enum codecs - #61

Merged
nuskey8 merged 1 commit into
nuskey8:mainfrom
farhan-syah:perf/enum-codec-split
Aug 4, 2026
Merged

optimize: use inline hint instead of inline(always) for enum codecs#61
nuskey8 merged 1 commit into
nuskey8:mainfrom
farhan-syah:perf/enum-codec-split

Conversation

@farhan-syah

@farhan-syah farhan-syah commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #60.

Changes the two derive-generated codec functions from #[inline(always)] to #[inline]. Every hand-written #[inline(always)] in zerompk/src/impl.rs and zerompk/src/lib.rs is left exactly as it is — those bodies are a few instructions on a hot path and the attribute is right for them.

These two are the only sites whose body size is chosen by the user's type rather than by the library. A derived enum decoder grows with the variant count, and forcing it inline means a parent enum that wraps several op enums becomes one
function containing all of their decoders. LLVM's passes are superlinear in function size, so the cost grows far faster than the type does — on the 50-line reproduction in #60, a crate-only rebuild goes from 28.90s to 0.82s.

#[inline] still lets the cost model inline the small cases, which is nearly all of them.

Verification

  • zerompk's own suite: unchanged. The 5 failures in tests/derive.rs are present identically on a pristine main worktree, so they are not from this change.
  • Downstream: a database codebase using zerompk for its internal wire format has a 6k-line crate of plan enums that went from 32 minutes to 44 seconds to compile, with its full suite of 13,633 tests — all of which exercise the encode/decode paths — passing unchanged.

I did not measure a runtime effect. The change only removes a forcing attribute, so small codecs are still inlined by the cost model.

@nuskey8

nuskey8 commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Thank you for the PR.

I would like to accept this change, but the comment in the relevant section seems redundant. Could you limit the change to just the #[inline(always)] -> #[inline]?

@farhan-syah
farhan-syah force-pushed the perf/enum-codec-split branch from bb3156c to d24a150 Compare August 4, 2026 07:33
@farhan-syah

Copy link
Copy Markdown
Contributor Author

Thank you for the PR.

I would like to accept this change, but the comment in the relevant section seems redundant. Could you limit the change to just the #[inline(always)] -> #[inline]?

Done

@nuskey8
nuskey8 merged commit 75d527f into nuskey8:main Aug 4, 2026
2 checks passed
@nuskey8

nuskey8 commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Merged the PR. Thanks!

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.

derive: #[inline(always)] on generated codecs makes compile time explode for large enums (35x on a 50-line repro)

2 participants