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

Draft
fanquake wants to merge 7 commits from tidy_perf_padding into master AGit
fanquake commented 2026-11-09 17:49:36 +00:00 (Migrated from github.com)

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.

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 commented 2026-11-09 17:49:44 +00:00 (Migrated from github.com)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36819 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36819.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36819#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | Concept ACK | [sedited](https://github.com/bitcoin/bitcoin/pull/36819#issuecomment-6747838497), [jonatack](https://github.com/bitcoin/bitcoin/pull/36819#pullrequestreview-5830703280), [hodlinator](https://github.com/bitcoin/bitcoin/pull/36819#issuecomment-6748313870), [bartoli](https://github.com/bitcoin/bitcoin/pull/36819#issuecomment-6751334417) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36736](https://github.com/bitcoin/bitcoin/pull/36736) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36736.svg"></sub> (net: unify send pause state by l0rinc) * [#35940](https://github.com/bitcoin/bitcoin/pull/35940) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35940.svg"></sub> (net: add bip152hb permission to select BIP152 high-bandwidth peers by w0xlt) * [#35027](https://github.com/bitcoin/bitcoin/pull/35027) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35027.svg"></sub> (net: add -outboundbind option for outgoing source address by 8144225309) * [#34872](https://github.com/bitcoin/bitcoin/pull/34872) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34872.svg"></sub> (wallet: fix mixed-input transaction accounting in history RPCs by w0xlt) * [#27865](https://github.com/bitcoin/bitcoin/pull/27865) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/27865.svg"></sub> (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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

🔵 Suggestion · The fatal padding gate also constrains test fixtures and single-instance types

The tidy gate also constrains a five-element test fixture and node-wide single-instance objects, while an isolated 8-byte per-object regression remains below its threshold.

Location: src/.clang-tidy:25 (head).

Review coverage was incomplete.


Reviewed: 2d1b3f97d9d5 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:312ddb2095238aa2ca395a9cc39b05ab5a38a7177afbdb0d69098df9c3e0bef9:9a7f127b15c6116c267953d38288a9f17ec7c7bcd3a975fb71a2db8bfd974dbf --> <!-- ralph-base:afedb19cca4c3b40d89514fb0c66b0c20e4f5d62 --> <!-- ralph-head:2d1b3f97d9d52a3f188c701dc6d04df3769dd4c6 --> <!-- ralph-case:8439cfc7f460152af079cc505ca0443faefa55843e1298c9e08933656eab3875 --> **🔵 Suggestion · The fatal padding gate also constrains test fixtures and single-instance types** The tidy gate also constrains a five-element test fixture and node-wide single-instance objects, while an isolated 8-byte per-object regression remains below its threshold. Location: [`src/.clang-tidy:25`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/2d1b3f97d9d52a3f188c701dc6d04df3769dd4c6/src/.clang-tidy#L25>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`2d1b3f97d9d5`](<https://git.fish.foo/bitcoin/bitcoin/commit/2d1b3f97d9d52a3f188c701dc6d04df3769dd4c6>) · [Review report](<https://review.fish.foo/report/36819-2d1b3f97d9d52a3f188c701dc6d04df3769dd4c6-3284-2.html>) · [Previous reports](<https://review.fish.foo/traces/36819/>) [permalink](<https://review.fish.foo/report/36819-2d1b3f97d9d52a3f188c701dc6d04df3769dd4c6-3284-2.html>)
sedited commented 2026-11-09 18:16:09 +00:00 (Migrated from github.com)

Concept ACK, seems worthwhile to me.

Concept ACK, seems worthwhile to me.
jonatack (Migrated from github.com) reviewed 2026-11-09 18:30:15 +00:00
jonatack (Migrated from github.com) left a comment

Concept ACK, modulo keeping guarded members near their mutex and avoiding churn or grouping members less logically where it provides negligible benefit

Concept ACK, modulo keeping guarded members near their mutex and avoiding churn or grouping members less logically where it provides negligible benefit
hodlinator commented 2026-11-09 18:40:46 +00:00 (Migrated from github.com)

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.

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 commented 2026-11-09 18:51:48 +00:00 (Migrated from github.com)

🚧 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.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `tidy`: https://github.com/bitcoin/bitcoin/actions/runs/42668387091/job/129338067669</sub> <sub>LLM reason (✨ experimental): CI failed because clang-tidy flagged excessive struct padding in `ValidVector` in `test/bip352_tests.cpp`; warnings are treated as errors.</sub> <details><summary>Hints</summary> 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. </details>
bartoli commented 2026-11-09 21:00:17 +00:00 (Migrated from github.com)

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?

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 commented 2026-11-10 07:16:36 +00:00 (Migrated from github.com)

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 (https://github.com/bitcoin/bitcoin/pull/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.

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 (https://github.com/bitcoin/bitcoin/pull/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 (Migrated from github.com) reviewed 2026-11-10 07:17:08 +00:00
maflcko (Migrated from github.com) left a comment

.

.
maflcko (Migrated from github.com) commented 2026-11-10 07:08:26 +00:00

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

if memory usage was a concern here, those should be string_view
Lines 200-202
maflcko (Migrated from github.com) commented 2026-11-10 07:17:03 +00:00

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

splitting this up makes the code harder to read for no benefit?
l0rinc commented 2026-11-12 13:20:14 +00:00 (Migrated from github.com)

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.

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 commented 2026-11-27 17:18:23 +00:00 (Migrated from github.com)

🚧 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.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `tidy`: https://github.com/bitcoin/bitcoin/actions/runs/46029168189/job/140608243349</sub> <sub>LLM reason (✨ experimental): tidy_fail: clang-tidy reports excessive padding in `ValidVector` in `test/bip352_tests.cpp`, and warnings are treated as errors.</sub> <details><summary>Hints</summary> 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. </details>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36819
No description provided.