build: guard forced inlining #35573

pull l0rinc wants to merge 2 commits into bitcoin:master from l0rinc:l0rinc/guard-forced-inlining changing 5 files +22 −17
  1. l0rinc commented at 1:27 PM on June 21, 2026: contributor

    Problem: This is a follow-up to the force-inline discussion in https://github.com/bitcoin-core/secp256k1/pull/1859#pullrequestreview-4491819905.

    Fix: Rename ALWAYS_INLINE to FORCE_INLINE, matching the secp256k1 follow-up naming, and gate forced inlining to optimized non-size builds. We currently have only a few FORCE_INLINE call sites, and this PR changes those cases narrowly: optimized non-size builds keep forced inlining, while debug, no-inline, size-optimized, and unknown compiler modes fall back to plain inline.

    Size check: Linux bitcoind sizes from the reproducer below.

    Config Base Guard
    Debug 202,587,200 202,313,624
    Release 19,117,016 19,117,016
    RelWithDebInfo 309,241,040 309,241,040
    MinSizeRel 14,539,624 14,515,016

    Reproducer:

    <details><summary>`bitcoind` size comparisons</summary>

    COMMITS="1a2523e901a6c7c876c8a0817601e77d83f394b9 0c4d6e95946626bffbd9f0e9587d5a9819dbdd77" && \
    ROOT=$(mktemp -d) && OLD=$(git symbolic-ref --short -q HEAD || git rev-parse HEAD) && \
    trap 'git switch -q "$OLD" 2>/dev/null || git switch -q --detach "$OLD"' EXIT && \
    for commit in $COMMITS; do \
      git switch -q --detach "$commit" && short=$(git rev-parse --short=12 HEAD) && \
      for cfg in Debug Release RelWithDebInfo MinSizeRel; do \
        b="$ROOT/$short-$cfg" && log="$b.log" && \
        cmake -S . -B "$b" -G Ninja -DCMAKE_BUILD_TYPE="$cfg" >"$log" 2>&1 && \
        cmake --build "$b" -j "$(nproc)" --target bitcoind >>"$log" 2>&1 && \
        printf '%s %s %s\n' "$short" "$cfg" "$(stat -c%s "$b/bin/bitcoind")" || { cat "$log"; exit 1; }; \
      done; \
    done
    

    </details>

    Note: Rebase this change on #35215 to exercise more representative FORCE_INLINE call sites.

  2. build: guard forced inlining
    `ALWAYS_INLINE` currently expands to compiler-specific force-inline spellings even when inlining is disabled, optimization is off, or size optimization is selected.
    Use forced inlining only for optimized non-size builds and fall back to plain `inline` for debug, no-inline, size-optimized, and unknown compiler modes.
    Define `__OPTIMIZE_SIZE__` for MSVC `MinSizeRel` builds so the source guard sees the same size-optimization signal that GCC and Clang expose.
    
    Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
    8acbbdddd5
  3. scripted-diff: rename ALWAYS_INLINE to FORCE_INLINE
    The macro no longer always forces inlining after the guard change, so use the same FORCE_INLINE naming as the secp256k1 follow-up.
    
    -BEGIN VERIFY SCRIPT-
    git grep -q '\<FORCE_INLINE\>' -- src && { echo "Error: FORCE_INLINE already exists in src"; exit 1; }
    perl -pi -e 's/\bALWAYS_INLINE\b/FORCE_INLINE/g' $(git grep -l '\<ALWAYS_INLINE\>' -- src)
    -END VERIFY SCRIPT-
    775aaaf963
  4. DrahtBot added the label Build system on Jun 21, 2026
  5. DrahtBot commented at 1:27 PM on June 21, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35573.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  6. sedited commented at 3:36 PM on June 21, 2026: contributor

    Can you restate the motivation for the changes here clearly? I think we've had a discussion about inlining for debug builds somewhere, but can't seem to find it.

  7. l0rinc commented at 3:41 PM on June 21, 2026: contributor

    Can you restate the motivation for the changes here clearly?

    It's a follow-up to the force-inline discussion in https://github.com/bitcoin-core/secp256k1/pull/1859#pullrequestreview-4491819905 where @hebasto wrote:

    The Bitcoin Core project has a similar macro named ALWAYS_INLINE. Could we adopt SECP256K1_ALWAYS_INLINE here for consistency across the two closely related projects?

  8. hebasto commented at 1:53 PM on June 23, 2026: member

    Can you restate the motivation for the changes here clearly?

    It's a follow-up to the force-inline discussion in bitcoin-core/secp256k1#1859 (review) where @hebasto wrote:

    The Bitcoin Core project has a similar macro named ALWAYS_INLINE. Could we adopt SECP256K1_ALWAYS_INLINE here for consistency across the two closely related projects?

    I made that comment hoping to avoid a rename in this repo.

  9. l0rinc commented at 6:09 PM on June 23, 2026: contributor

    I made that comment hoping to avoid a rename in this repo.

    It wouldn't be fair to call it "always" when this PR is exactly about prohbiting it in certain cases - like we did in the secp repo. Is your suggestion avoiding the guard and always inlining instead, i.e. drop the PR?

  10. sipa commented at 6:13 PM on June 23, 2026: member

    I don't think we care about optimizing for size here?

  11. l0rinc commented at 6:22 PM on June 23, 2026: contributor

    I don't think we care about optimizing for size here?

    Shouldn't we disable MinSizeRel in that case? And wouldn't we get better debug stacks if we avoid forcing the inlines in those cases?

  12. maflcko commented at 7:25 AM on June 25, 2026: member

    It is a bit hard to follow the pull description. It first states that the problem is the naming, then claims to fix the naming. Then continues that it is also fixing minrelsize. Then, it claims a less-than 1% improvement in size?

    Can you state the motivation and the relevance of the fix in your own words in two sentences?

  13. l0rinc commented at 1:09 PM on June 25, 2026: contributor

    Can you state the motivation and the relevance of the fix

    When build options like Debug/MinSizeRel specifically request that aggressive optimizations be avoided, forced inlining is still applied here, unlike in secp256k1 where it was explicitly requested that those options be respected and the fix be ported back to Core. After gating on the build type, the name ALWAYS_INLINE is no longer accurate since inlining is no longer always forced. Since it wasn't used extensively in Core, I provided an example PR which exercises this inline-forcing.

    Closing for lack of interest.

  14. l0rinc closed this on Jun 25, 2026

  15. l0rinc deleted the branch on Jun 25, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-07-01 05:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me