I'm recently reading the source code of sqlite3. In the amalgamation version, there are only four files. On the official website, they say that:
"the amalgamation also makes it run faster"
"We have measured performance improvements of between 5 and 10% when we use the amalgamation to compile SQLite rathe开发者_JAVA百科r than individual source files."
I don't understand how they make it and why. Does anyone have any ideas? Do we have any tools available for doing that?
You can have similar result if you parse all .c file, extract all #include
s, then build a huge file that first lists all includes, then lists all the other content of those .c files.
This way you have all code in a single translation unit which allows the compiler to see all code at once and perform better optimizations. This is relevant for most C compilers yet newest compilers feature so-called link-time code generation that allows the compiler to see code of multiple translation units at once (at link time) and generate better code even without the amalgamation trick.
精彩评论