Arduino Playground is read-only starting December 31st, 2018. For more info please look at this Forum Post

Arduino-0007 code size optimization patch

This patch has been incorporated into Arduino 0008, which you can download from the Arduino software page.

This patch allows you to shrink your sketch dramatically!


Install

  • exit the Arduino GUI if you are running it.
  • download a7patch_2007_02_19.zip
  • unzip a7patch_2007_02_19.zip at the Arduino install root (example : c:/home/nrd/arduino-0007). Be sure to include directories of unzipped files, so they go into the proper paths.
  • Macintosh users must rename <arduino-root>/lib/pde.jar to <arduino-root>/lib/Arduino.jar


Uninstall

  • exit the Arduino GUI if you are running it.
  • remove the directory <arduino-root>/lib/targets/arduino/
  • rename the directory <arduino-root>/lib/targets/arduino.original/ to <arduino-root>/lib/targets/arduino/
  • remove the directory <arduino-root>/lib/processing/
  • rename the file <arduino-root>/lib/pde.jar (Arduino.jar on Macintosh) to <arduino-root>/lib/pde.jar.patched
  • Macintosh users must rename <arduino-root>/lib/pde.jar.original to <arduino-root>/lib/Arduino.jar
  • Non-Macintosh users must rename <arduino-root>/lib/pde.jar.original to <arduino-root>/lib/pde.jar


Use it

  • Run the Arduino IDE and make your sketch exactly as you used to.


How it works

  • Instead of linking against .o object files, we use .a library files. This way we can remove unused code. (See /lib/processing/app/Compiler.java source code.)
  • The runtime library has been broken up into more files, to increase the ability of the linker to exclude code that your sketch doesn't use.
  • The function main() has been moved from /lib/targets/arduino/wiring.c to main.cxx. The contents of main.cxx is appended to the contents of your sketch.pde, in the file applet/sketch.cpp, before compiling. (See /lib/processing/app/preproc/PdePreprocessor.java writeFooter source code).


Warnings/Issues

  • Has been tested on Windows platform only. I would like feedback from Macintosh/Linux users (see link below).
  • Does not yet work if you use makefile to build; only works for Arduino IDE and Windows batch file build.
  • If you run into any problems, please let me know by posting to:
    http://forum.arduino.cc/index.php/topic,36752


Files included in this patch

  • lib/processing/app/Compiler.java
  • lib/processing/app/preproc/PdePreprocessor.java
    Java source code for modifications to Arduino IDE.
    These cause the IDE to compile the runtime source into
    libraries (.a) instead of object (.o) files.

  • lib/pde.jar
    Compiled Java classes for Arduino IDE.
    This is what actually gets executed on your machine.

  • lib/pde.jar.original
    The original Arduino 0007 Java runtime, as a backup 
    for uninstalling this patch.

  • README.txt
    A copy of these instructions for reading offline.

  • lib/targets/arduino/*
    Modified versions of standard Arduino runtime library.
    The function main() was split out into its own file,
    because it does not work to have main() in a library!
    Now main() is appended to your sketch source and compiled
    with it.  Also, the source code files have been broken
    up into smaller pieces to make library linking more efficient
    at generating small code.

  • lib/targets/arduino.original/*
    The original standard version of runtime source code.
    This allows you to put Arduino back the way it was before
    this patch, in case you don't like the patch.
    (See above UNINSTALL instructions.)