[Toybox] Impact of global struct size

Ray Gardner raygard at gmail.com
Sat Dec 30 16:10:12 PST 2023


I am having a bit of trouble understanding the impact of globals.

There are the probes GLOBALS and findglobals to see what the space usage
is for globals. The output of both show that "this" is up to 8232 bytes,
due to the "ip" toy using 8232 of global space.

The blog entry of 31 August 2023 ends with some discussion of which
commands take up the most global space. It says "Everything "tr" and
earlier is reasonably sized, and "ip" and "telnet" are in pending."
I inferred that this means commands in pending are less important here,
but they still seem to take up space in "this".

How important is the space here? "tr" was 520 then, cksum was 1024. How
big is too big?

As long as "this" is as big as the largest GLOBAL struct, then what is the
point of working to reduce the global space of any command, when the space
for "ip" is in there whether "ip" is compiled into toybox or not? What am
I missing? Why are global structs included in globals.h for commands not
included in a build? Or are they somehow suppressed in the build?

The globals do not seem to affect the size of the executable file, at
least using the default build. Is the issue with "this" taking up space at
runtime? Many commands must surely allocate much more space dynamically
anyway.

I ask because I have been spending effort to reduce global usage in a toy
I'm working on, and did some rather large changes of static structs to
pointer-to-struct to reduce global from 960 to 336, saving 624 global
bytes, but the code size increased by 285 just due to accessing via
pointers in many places. I don't yet know if that has impacted performance
noticeably. I am trying to understand if I should back out these changes
before doing more work.


More information about the Toybox mailing list