Ideas on how to reduce size of settings_t struct
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 14.1k
- Forks
- 2.2k
- Avg merge
- 7h 35m
- Merged PRs (30d)
- 51
Description
settings_t as defined in configuration.h is massive right now in terms of size.
Settings are divided into types - bools, ints, unsigned integers, char array variables, and floats. Bools are 8 bits in size, ints 32-bit signed, unsigned integers 32bit unsigned, and char arrays are of variable fixed-width sizes.
All of these variables are starting to add up:
- signed integers (32bit) - 15 entries = 15 * 32 bits = 480 bits
- unsigned integers (32bit) - 158 entries = 158 * 32 bits = 5056 bits
- bools (8bit) - 339 entries = 339 * 8 bits = 2712 bits
- floats (32bit) - 47 entries = 47 * 32 bits = 1504 bits
- char arrays - not counted, of varying sizes.
Even though settings is allocated on the heap, size reductions could help. Some ideas on how we can reduce the size of this struct:
- We do not need 32 bits for every unsigned/signed variable in this config struct. Depending on the max value that can be inputted for a given setting, 8bits or 16bits might just be enough. One of the solutions could be splitting up unsigneds into 8bit, 16bit and 32bit. For example, if a setting's max value can only reach 256, then we can downgrade the unsigned variable to an 8bit unsigned variable.
- Instead of using a separate bool variable per setting, we could use unsigned 32bit variables instead and then use bitmasks. We would have to group these logically and intelligently since each 32bit unsigned variable would only be able to hold 32 flags.
With 11 unsigned 32bit values, we could cover 352 boolean settings. 11 * 32 = 352 bits. This would be a big reduction from the current 2712 bits that the boolean settings currently occupy. - Look into the char arrays and ways we could reduce their sizes. Perhaps we can work more with base paths instead of full paths and assemble the full path on the fly at runtime before it is actually needed, that way we wouldn't have to store it in a huge MAX_PATH_LENGTH variable.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with settings_t in configuration.h and trace how its fields are allocated and used throughout the project. Compare the sizes and constraints of the integer, boolean, float, and character-array settings before choosing an approach. Done means reducing the struct's memory usage without changing setting behavior or supported values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100