pythoncoder wrote: ↑Thu Aug 05, 2021 5:09 am
I had formed the idea that a worthwhile optimisation was to use short names (and to re-use them).
This was my understanding too
pythoncoder wrote: ↑Thu Aug 05, 2021 5:09 am
The docs indicate that names no longer than 10 characters get interned as qstrs.
This specifically applies to literal strings. Anything used as an identifier will always become a QSTR regardless of length.
(Surprisingly this applies not just to globals but also locals -- the parser/compiler needs to track them, and then has no way to free them afterwards because they may be dupes).
pythoncoder wrote: ↑Thu Aug 05, 2021 5:09 am
I then modified the code to shorten all function names to < 10 chars, e.g. in this case _u_int. I couldn't measure any difference in RAM use (running on a Pyboard 1.1).
This is suprising to me but I don't have a good explanation.
Probably the best diagnostic is to run
and see if there is a difference in the amount of ram used for interned string data.
QSTR data is stored in two places -- the pools (which are a linked list of pointers to the start of the strings), and the actual packed string data (which are stored in chunks allocated on the heap). The pool usage is only proportional to the number of strings. Chunks are allocated by either growing the previous chunk by the required amount, or starting a new chunk. New chunks start at 128 bytes.
So it's possible that fragmentation in the chunks is leading to the same total memory usage... but this seems like an amazing coincidence.