title: Can we reduce ESP IDF boiler plate size?
body: <p>I tested running bare bones code using ESP IDF on an ESP32 chip using duinotech XC-3800, and obtained the following results in terms of image size.</p>
  
  <h1>Analysis Binary Size for ESP32</h1>
  
  <h2>Folder Structure</h2>
  
  <ul>
  <li>temp/
  
  <ul>
  <li>main/
  
  <ul>
  <li>CMakeLists.txt</li>
  <li>main.c</li>
  </ul></li>
  <li>CMakeLists.txt</li>
  </ul></li>
  </ul>
  
  <h2>File contents</h2>
  
  <h3>CMakeLists.txt</h3>
  
  <pre><code># The following lines of boilerplate have to be in your project's
  # CMakeLists in this exact order for cmake to work correctly
  cmake_minimum_required(VERSION 3.5)
  
  include($ENV{IDF_PATH}/tools/cmake/project.cmake)
  project(temp)
  </code></pre>
  
  <h3>main>CMakeLists.txt</h3>
  
  <pre><code>idf_component_register(SRCS "main.c"
                      INCLUDE_DIRS "")
  </code></pre>
  
  <h3>Test 1 main>main.c</h3>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void app_main(void) {
    printf("Hello world!\n");
    for (int i = 10; i &gt;= 0; i--) {
      printf("Restarting in %d seconds...\n", i);
    }
    printf("Restarting now.\n");
    fflush(stdout);
  }
  
  </code></pre>
  
  <h3>Test 2 main>main.c</h3>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void app_main(void) { printf("Hello world!\n"); }
  
  </code></pre>
  
  <h3>Test 3 main>main.c</h3>
  
  <pre><code>void app_main(void) {}
  
  </code></pre>
  
  <h2>Size comparison</h2>
  
  <p>Obtained by running <code>idf_size.py build/temp.map</code></p>
  
  <h3>Test 1</h3>
  
  <pre><code>Total sizes:
   DRAM .data size:    8320 bytes
   DRAM .bss  size:    4072 bytes
  Used static DRAM:   12392 bytes ( 168344 available, 6.9% used)
  Used static IRAM:   38804 bytes (  92268 available, 29.6% used)
        Flash code:   75408 bytes
      Flash rodata:   23844 bytes
  Total image size:~ 146376 bytes (.bin may be padded larger)
  </code></pre>
  
  <h3>Test 2</h3>
  
  <pre><code>Total sizes:
   DRAM .data size:    8320 bytes
   DRAM .bss  size:    4072 bytes
  Used static DRAM:   12392 bytes ( 168344 available, 6.9% used)
  Used static IRAM:   38804 bytes (  92268 available, 29.6% used)
        Flash code:   75240 bytes
      Flash rodata:   23796 bytes
  Total image size:~ 146160 bytes (.bin may be padded larger)
  </code></pre>
  
  <h3>Test 3</h3>
  
  <pre><code>Total sizes:
   DRAM .data size:    8320 bytes
   DRAM .bss  size:    4072 bytes
  Used static DRAM:   12392 bytes ( 168344 available, 6.9% used)
  Used static IRAM:   38804 bytes (  92268 available, 29.6% used)
        Flash code:   75004 bytes
      Flash rodata:   23780 bytes
  Total image size:~ 145908 bytes (.bin may be padded larger)
  </code></pre>
  
  <h2>Analysis</h2>
  
  <p>Size for code obtained by running <code>stat --format="%s" main/main.c</code></p>
  
  <p>All Sizes are in Bytes</p>
  
  <pre><code>Test No. | Code |  Image | Flash Code | Flash rodata
  -------- | -----| ------ | ---------- | ------------
         1 |  207 | 146376 |      75408 |        23844
         2 |   70 | 146160 |      75240 |        23796
         3 |   43 | 145908 |      75004 |        23780
  </code></pre>
  
  <p>At least 145KB of boiler plate code just to get an empty main run.</p>
  
  <h2>Speculation</h2>
  
  <p>I suspect that the 145KB is made up of a number of libraries that are always loaded onto the chip whether you use them or not. Some of them must be the <code>FreeRTOS</code>, <code>WiFi</code>, <code>HTTP</code> etc.</p>
  
  <p>Can we bring down this size somehow and load only the bare minimum required for operation?</p>