Skip to content

What change caused the largest reduction in code size? #264

Answered by charlesnicholson
AJ528 asked this question in Q&A
Discussion options

You must be logged in to vote

Yup, it gets really hard to keep things really tiny in C, and as soon as you drop into ASM you hit portability issues. Off the top of my head, there wasn't a single silver bullet, it was as you say: just constantly pasting the code into godbolt and studying the asm.

Big wins:

  • making all of the internal helper functions static and never taking their addresses. That allows the compiler to go crazy with inlining, which removes function prologue / epilogue work and doesn't waste bytes on argument passing.
  • using sibling-call optimization in npf_putc_cnt to increment the output buffer cursor for free, instead of having to increment the output buffer cursor at every point in npf_vpprintf where …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@AJ528
Comment options

@charlesnicholson
Comment options

Answer selected by AJ528
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants