draft: The Hidden Cost of Misalignment#622
Open
chrismerck wants to merge 4 commits intomemfault:masterfrom
Open
draft: The Hidden Cost of Misalignment#622chrismerck wants to merge 4 commits intomemfault:masterfrom
chrismerck wants to merge 4 commits intomemfault:masterfrom
Conversation
## 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>
Contributor
Author
|
Statement on the use of AI in the preparation of this post: I heavily used Claude Code / superpowers in developing |
Member
|
Thank you @chrismerck for submitting! This post looks great. We'll formally review this as soon as we can |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 packwas 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.