phalcon/cphalcon — pull request #1785 by sjinks (2014-01-10 23:25:56+00:00)
Title: Major Source code optimization

In brief, what has been done:
* all header files had [include guards](http://en.wikipedia.org/wiki/Include_guard) added
* arginfo and class method tables were moved from headers to sources (exception: interfaces and bases classes have arginfo in the header — this allows to reuse it by the child classes and interface implementors)
* source files do not `#include "phalcon.h"` anymore — they #include only the files they need
* zend_class_entry definitions were moved from phalcon.c to respective source files — now if someone needs to add a new class, there are less places in the code to modify
* gcc-compatible compilers are instructed to generate dependency files (*.d): this is what automake usually does but because PHP uses only autoconf, this had to be done manually (pros: if you change a file, all dependent files need to be rebuilt. Before this, if you touch a header file, `make` won't rebuild anything and you need to rebuild the entire project).

Why this is good:
* the compiler has to process fewer files (when the source file #include'd phalcon.h, the compiler had to process all headers regardless whether the source file needed them)
* include guards will allow to use static inline functions in the headers — this could be used to replace macros (functions are type safe, macros aren't)
* less symbols are exposed, this reduces the size of the debug information and allows for extra optimizations.

Benchmarks:

**1.3.0 branch**
```
$ du -hs ext
7,5M ext

$ cd ext; time sh -c 'phpize --clean && phpize && ./configure CFLAGS="-O1 -g -Wall -Werror" && make -B -j75 install'

real 1m37.913s
user 3m17.824s
sys 0m46.596s

Max LA: 55.12

$ du -h modules/phalcon.so

193M modules/phalcon.so

$ NO_INTERACTION=1 make test

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped : 0
Exts tested : 46
---------------------------------------------------------------------

Number of tests : 91 85
Tests skipped : 6 ( 6.6%) --------
Tests warned : 0 ( 0.0%) ( 0.0%)
Tests failed : 0 ( 0.0%) ( 0.0%)
Expected fail : 0 ( 0.0%) ( 0.0%)
Tests passed : 85 ( 93.4%) (100.0%)
---------------------------------------------------------------------
Time taken : 28 seconds
=====================================================================
```

**This branch:**
```
$ du -hs ext
7,6M ext

$ cd ext; time sh -c 'phpize --clean && phpize && ./configure CFLAGS="-O1 -g -Wall -Werror" && make -B -j75 install'

real 0m41.058s
user 1m13.126s
sys 0m37.876s

Max LA: 30.77

$ du -h modules/phalcon.so
9,6M modules/phalcon.so

$ NO_INTERACTION=1 make test

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped : 0
Exts tested : 46
---------------------------------------------------------------------

Number of tests : 91 85
Tests skipped : 6 ( 6.6%) --------
Tests warned : 0 ( 0.0%) ( 0.0%)
Tests failed : 0 ( 0.0%) ( 0.0%)
Expected fail : 0 ( 0.0%) ( 0.0%)
Tests passed : 85 ( 93.4%) (100.0%)
---------------------------------------------------------------------
Time taken : 10 seconds
=====================================================================
```

Summary:
* 1.3.0:
* compilation time: 1m37.913s
* max load average: 55.12
* binary size: 193M
* time taken for tests: 28 seconds
* this branch:
* compilation time: 41.058s (**58.07% faster**)
* max load average: 30.77 (**44.18% less**)
* binary size: 9.6M (**95.03% smaller**)
* time taken for tests: 10 seconds (**64% faster**)