Skip to content

[RFC] enable clang-tidy optin.performance.Padding - #36819

Draft
fanquake wants to merge 7 commits into
bitcoin:masterfrom
fanquake:tidy_perf_padding
Draft

fanquake wants to merge 7 commits into
bitcoin:masterfrom
fanquake:tidy_perf_padding

Conversation

@fanquake

@fanquake fanquake commented Nov 9, 2026

Copy link
Copy Markdown
Member

Enable optin.performance.Padding with the default of 24 bytes (made explicit in the clang-tidy config), after fixing warnings for more padding than that. Enabling it at this point would be to catch regressions above this amount.

Based on #36501, which reorders CBlockIndex to save 8 bytes (clang-tidy also warns about this). Wondering if contributors/reviewers think this is worthwhile given we may make that refactor? Also not sure if it's possible for us to enable this generally, as padding will differ depending on various factors.

@DrahtBot

DrahtBot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Concept ACK sedited, jonatack, hodlinator, bartoli

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36736 (net: unify send pause state by l0rinc)
  • #35940 (net: add bip152hb permission to select BIP152 high-bandwidth peers by w0xlt)
  • #35027 (net: add -outboundbind option for outgoing source address by 8144225309)
  • #34872 (wallet: fix mixed-input transaction accounting in history RPCs by w0xlt)
  • #27865 (wallet: Track no-longer-spendable TXOs separately by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@sedited

sedited commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Concept ACK, seems worthwhile to me.

@jonatack jonatack left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Concept ACK, modulo consider keeping guarded members near their mutex and avoiding churn or grouping members less logically where it provides negligible benefit (arguably the changes in rpc/client.cpp and txmempool.h).

@hodlinator

Copy link
Copy Markdown
Contributor

Concept ACK, probably good to turn this on by default with a reasonable threshold.

For singleton types (*Man etc), in cases where it really leads to less logical groupings of fields, one could opt out, like we do for recursion warnings today.

@DrahtBot

DrahtBot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task tidy: https://github.com/bitcoin/bitcoin/actions/runs/42668387091/job/129338067669
LLM reason (✨ experimental): CI failed because clang-tidy flagged excessive struct padding in ValidVector in test/bip352_tests.cpp; warnings are treated as errors.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@bartoli

bartoli commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Concept ACK for me too. I had not included other classes in the original PR because they are probably instantiated far less than 1 million times at once, so the changes seemed not worth it to me (sometimes members are ordered by fonctionality, code might be more understandable that way). But if there is now a CI check to avoid potentially losing more memory in the future, I'm all for it.

It seems the limit of 23 is not properly used though, since the CI output warns about a loss of 11 padding bytes?

@maflcko

maflcko commented Nov 10, 2026

Copy link
Copy Markdown
Member

Is this really worth it? This could make the code harder to read by having fields that belong together split further apart. See e.g. the mempool "rolling" section.

I'd say this should be an opt-in list for structs where we know they exist 1000s of times and that would benefit low-resource systems. E.g. saving 24kB on systems that have set 2000 connections (#35919), so likely they are not low-memory systems, seems a rounding error.

So my preference would be to have this opt-in per-struct and accommodate each change with a measurement, or at least a guess of how much it would save.

@maflcko maflcko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

.

Comment thread src/rpc/client.cpp

std::string methodName; //!< method whose params want conversion
int paramIdx; //!< 0-based idx of param to convert
std::string paramName; //!< parameter name

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if memory usage was a concern here, those should be string_view

Comment thread src/txmempool.h
Comment on lines 198 to 200
mutable int64_t lastRollingFeeUpdate GUARDED_BY(cs){GetTime()};
mutable bool blockSinceLastRollingFeeBump GUARDED_BY(cs){false};
mutable double rollingMinimumFeeRate GUARDED_BY(cs){0}; //!< minimum fee to get into the pool, decreases exponentially

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

splitting this up makes the code harder to read for no benefit?

@l0rinc

l0rinc commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Not sure the tidy check makes sense (as @maflcko also mentioned, for classes with only a few instances in total, readability can matter more), but we could keep this open as a guide for similar changes, so we can consider them on a case-by-case basis.

@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task tidy: https://github.com/bitcoin/bitcoin/actions/runs/46029168189/job/140608243349
LLM reason (✨ experimental): tidy_fail: clang-tidy reports excessive padding in ValidVector in test/bip352_tests.cpp, and warnings are treated as errors.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • Intermittent network issues can occur; re-run CI for now, and report the issue if they keep happening.

  • A functional or integration test failure may be intermittent or unrelated to this pull request.
    If no dedicated issue thread exists, create a new one to track it.

Leave a comment here, if you need help tracking down a confusing failure.

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.

8 participants