Tips and Tricks to reduce code size (unused code)
ags
Posts: 386
I'm running into memory limits and am looking for ways to reduce code size. One obvious thought is to remove unused code. At the same time, I would like to create "packages" - i.e. SPIN objects - to promote reuse. Whenever an element in an object (PUB) is used more than once that's saving memory. However, after running a simple test case comparing the complied size of a SPIN file with and without an unused (uncalled) PUB method, it appears that the method is included in the compiled code.
Other than having to manually trim out any unused methods, what tips and/or tricks are there to address this challenge?
Thanks.
Other than having to manually trim out any unused methods, what tips and/or tricks are there to address this challenge?
Thanks.
Comments
Add this to Other Compiler Options: -Ogcrux
This is the bstc options help.
Are the only other alternatives that come to mind: a) create objects that have few methods (or methods that are always used together) or b) manually prune for each usage?
@jazzed: I'll give this a try when I get to my "other" machine. Thanks.
If you are open to other alternatives, there is at least one that works quite well but is not spin code per se.
If you can use forth, propforth has a simple solution.
Using the SD kernel, the propforth kernel runs on the prop, and has the ability to call "files" from the SD. The SD "files" can be scripts of forth words, and need not include additional definitions. The scripts can be loaded from SD and executed on the fly. Each cog can load and execute scripts. Each cog can execute any sequence of scripts. A well crafted application could exist as a series of calls to SD script files, and you can go as big as you please. If you create your log or other output file last, it can be as big as the remaining SD. Otherwise just reserve space the max size you need.
Since script loading and execution happens on the fly, the transfer time for the SD is not a bottleneck (at least its been negligible so far). SD transfer time only becomes an issue if you create huge log files (greater than many megagbytes) then you have to wait when you transfer these to the PC, as the propforth files are not directly compatible with FAT file system. A logfile of 180 megs took like a day to transfer to the PC. Of course you could write a PC side driver program to speed this up, but that has not been needed so far.