AVR like other small microcontrollers have very limited resources including speed, SRAM and Flash. Before you get to the middle of your program writing you may notice that you running out of one of those. You may be struggling with exceeding SRAM, or loosing execution speed where you need it most or simply run out of program space. There are times when there is nothing you can do except to look for bigger and faster MCU, but in some cases smart coding tricks may help. Atmel team have prepared pretty good application note where they take through various aspects of code optimization.
Following those advises they managed to reduce code size by 100%, SRAM by 56.5% and execution speed by 33%. Their example was about reading ADC and sending data via USART. Generally speaking they pointed variable sizes – don’t forget that AVR is 8-bit MCU, so using bigger variables always lead to bigger code size and slower processing. Also few tricks allows reduce loop size and speed. Sometimes simple loop enrolling may give a nice kick. Each optimization trick is followed by example with side by side code chunks and resulting compiler output. Might be few tricks you are already using, but when everything is nicely documented it is always worth to have in your library.