合并sqlite [英] amalgamation sqlite

查看:16
本文介绍了合并sqlite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近在看sqlite3的源代码.在合并版本中,只有四个文件.在官方网站上,他们说:

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"

当我们使用合并来编译 SQLite 而不是单独的源文件时,我们测量了 5% 到 10% 的性能改进."

"We have measured performance improvements of between 5 and 10% when we use the amalgamation to compile SQLite rather 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?

推荐答案

如果你解析所有 .c 文件,提取所有 #include ,然后构建一个大文件,你会得到类似的结果列出所有包含,然后列出那些 .c 文件的所有其他内容.

You can have similar result if you parse all .c file, extract all #includes, then build a huge file that first lists all includes, then lists all the other content of those .c files.

通过这种方式,您可以将所有代码放在一个翻译单元中,这样编译器就可以一次查看所有代码并执行更好的优化.这与大多数 C 编译器相关,但最新的编译器具有所谓的 链接时代码生成功能 允许编译器一次查看多个翻译单元的代码(在链接时),即使没有合并技巧也能生成更好的代码.

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.

这篇关于合并sqlite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆