Optimizing code for size/firmware customization

Question for the more experienced out there. What are some best practices for minimizing my code and squeezing it down as tight as possible? In the same vane, is it possible/advisable to cut certain unneeded modules from the baseline Particle firmware? For instance, if I’m only using SPI and wifi can I cut out the i2c and other nonessential pieces?