Skip to content

draft: The Hidden Cost of Misalignment#622

Open
chrismerck wants to merge 4 commits intomemfault:masterfrom
bondhome:draft/packed-aligned
Open

draft: The Hidden Cost of Misalignment#622
chrismerck wants to merge 4 commits intomemfault:masterfrom
bondhome:draft/packed-aligned

Conversation

@chrismerck
Copy link
Contributor

I was speaking with an anonymous acquaintance who is expert in designing performance databases, and they gave me the idea to study how alignment impacts performance in embedded systems at Bond Home.

I thought we were in good shape, maybe just needing some lints to flag introducing unaligned fields into packed structs in our database and network protocols.

What I found surprised me: pragma pack was wrecking codegen, emitting 7x more instructions than expected.

This post shares the learnings from this, suggestions on how to pack efficiently (aligned and packed attributes can be combined), and to use a struct linter to catch alignment regressions as structs evolve over time.

chrismerck and others added 4 commits February 2, 2026 09:12
## User Prompt

"use superpowers writing style skill to review packed-aligned.md"

"use superpowers systemic debugging and subagent-driven approach to
validate each of the accuracy concerns above. in particular, download
the linked struct-lint repo as a subdir here and attempt to repro"

"This Isn't Platform-Specific --> needs better title, since it _is_
platform specific"

[SVGs, struct-lint repo, and Godbolt disassembly used for validation]

## Analysis

Writing review identified accuracy concerns and style improvements.
Technical review validated claims by reproducing disassembly with
struct-lint and cross-compiling for seven architectures.

## Implementation

- Rename title: "The Hidden Cost of Misalignment"
- Rename section: "Not Just RISC-V" (was "This Isn't Platform-Specific")
- Add fishtank intro linking to prior embedded-db post
- Expand arch table: MIPS32 (2x), macOS arm64 (1x), i686/x86_64 (1x)
- Add footnotes: endianness, aligned(8) for 64-bit, stride computation
- Add array-stride SVG showing pack(1) vs packed+aligned(4) layout
- Replace "instructions" with "ops" throughout for precision
- Remove verbose 64-bit disassembly listing (summarize as "14 ops")
- Remove redundant "Measured Results" table (covered by arch table)
- Show full reassembly instructions in read examples
- Clarify struct evolution risk: insertion vs append

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…tnotes

Per user prompts:
- "Why This Happens --> move to admonition block"
- "Catching Misalignment with struct-lint --> also move to admonition"
- "move the whole 'There's a bonus, too...' stuff as a footnote"
- "The stride difference has a second cost: address computation. --> remove,
  and add the footnote after 'each element is padded to 20 bytes',
  rewriting it to be simpler"

Changes:
- Convert "Why This Happens" section to blockquote admonition
- Convert "Catching Misalignment with struct-lint" to blockquote admonition
  with code block preserved inside
- Move battery_mv read bonus (asm examples) to footnote [^bonus],
  simplified to plain English
- Simplify stride footnote [^stride] and relocate inline

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chrismerck chrismerck requested a review from a team as a code owner February 26, 2026 15:34
@chrismerck chrismerck changed the title Draft/packed aligned draft: packed and aligned Feb 26, 2026
@chrismerck chrismerck changed the title draft: packed and aligned draft: The Hidden Cost of Misalignment Feb 26, 2026
@chrismerck
Copy link
Contributor Author

Statement on the use of AI in the preparation of this post: I heavily used Claude Code / superpowers in developing struct-lint, and to a significant degree in the writing of this post. I believe the points conveyed in the post are well grounded by virtue of application of struct-lint on a real codebase at bondhome, and through experiments with cross compilation and disassembly analysis. The post has already been positively reviewed by an industry expert. I stand by the resulting post as a strong example of my work.

@gminn
Copy link
Member

gminn commented Feb 28, 2026

Thank you @chrismerck for submitting! This post looks great. We'll formally review this as soon as we can

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.

2 participants