libretro / RetroArch

Cross-platform, sophisticated frontend for the libretro API. Licensed GPLv3.
http://www.libretro.com
GNU General Public License v3.0
9.96k stars 1.79k forks source link

Ideas on how to reduce size of settings_t struct #14027

Open LibretroAdmin opened 2 years ago

LibretroAdmin commented 2 years ago

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:

Even though settings is allocated on the heap, size reductions could help. Some ideas on how we can reduce the size of this struct:

ghost commented 2 years ago

Why not just use bitfields?

ZachCook commented 2 years ago

The char arrays are so large that anything else isn't worth changing yet.

There are about 100 char arrays, 58 are PATH_MAX_LENGTH and could be replaced with char *, would save memory for any path that is a few char shorter than it's current max size (PATH_MAX_LENGTH is 512 or 4096 depending on platform, usually the latter), this could easily save 20,000-200,000 bytes (160,000-1,600,000 bits for comparison to the bits listed above).

Would lose use of sizeof() but can always set size as PATH_MAX_LENGTH in strlcpy(), etc. The existing char * that reference them can either just be a copy of the pointer or could be changed to char ** if really needed to track changes.