Skip to content

lib: optimize struct layouts and reduce memory usage - #22585

Closed
bagder wants to merge 7 commits into
masterfrom
bagder/structs
Closed

bagder wants to merge 7 commits into
masterfrom
bagder/structs

Conversation

@bagder

@bagder bagder commented Aug 14, 2026

Copy link
Copy Markdown
Member

The key is to sort struct fields by size...

bagder added 7 commits August 14, 2026 14:38
- 'upgr101' from enum upgrade101 => 'unsigned char', saves three bytes
- made some 'unsigned char' => uint8_t
- moved 'io_flags' to fill a hole on 64-bit arch

Takes it down from 248 to 232 bytes with no functional change.
Sort the fields by size. Larger to smaller. Helps avoding holes.

- httpsig_algorithm moved
- FTP uint8_t fields moved
- new_file_perms moved
- rtspreq moved

1856 => 1832 bytes with no functional change.
It only had a single struct member 'weight'. Use that directly instead
to save indirections and struct alignments. Move field for size order.
- make 'pxcode' a uint8_t
- move 'conn_protocol' to fill a hole

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Optimizes internal data structures to reduce padding and memory usage without changing behavior.

Changes:

  • Reorders fields by size and narrows suitable enum storage.
  • Flattens HTTP/2 priority weight structures.
  • Updates all affected initialization and access sites.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/urldata.h Reorganizes internal structure layouts.
lib/url.c Updates priority initialization and reset.
lib/socks.c Stores proxy errors in narrowed storage.
lib/setopt.c Updates stream-weight assignment.
lib/request.h Compacts request state fields.
lib/http2.c Uses flattened priority weight fields.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@bagder
bagder marked this pull request as ready for review August 14, 2026 14:04
@bagder bagder closed this in fe703df Aug 14, 2026
@bagder
bagder deleted the bagder/structs branch August 14, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants