[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua "amalgamation" for 5-10% speed improvement and ease of use
- From: dcharno <dcharno@...>
- Date: Sun, 15 Feb 2009 12:49:07 -0500
I was reading the following page related to the SQLite project: http://www.sqlite.org/cvstrac/wiki?p=TheAmalgamation
and found this:
"In addition to making SQLite easier to incorporate into other projects, the amalgamation also makes it run faster. Many compilers are able to do additional optimizations on code when it is contained with in a single translation unit such as it is in the amalgamation. We have measured performance improvements of between 5 and 10% when we use the amalgamation to compile SQLite rather than individual source files."
This is an old thread, but ...
After using SQLite in a number of projects I really came to appreciate
the convenience of the amalgamation approach. etc/all.c helps quite a
bit, but it is nice dealing with fewer files.
The attached script makes amalgamated C and header files based upon
all.c. To use them in a project, just build in am-lua.c and include
am-lua.h. Maybe someone else finds it useful
--
-- Copy inputs to output, inlining any Lua #include once
--
local PREFIX = "am-"
local SRC_PATH = "../src/"
function CreateAmalgamation(ofilename, files)
local out = assert(io.open(ofilename, "w"))
local headers = { ["lua.c"]=true }
function CopyWithInline(filename)
if headers[filename] == nil then
headers[filename] = true
local inp = assert(io.open(SRC_PATH .. filename, "r"))
for l in inp:lines() do
local inc = l:match('#include "([^"]+)"')
if inc and (inc ~= "luaconf.h") then
CopyWithInline(inc)
else
out:write(l .. "\n")
end
end
end
end
for _, file in ipairs(files) do
CopyWithInline(file)
end
end
CreateAmalgamation(PREFIX.."lua.c", {"../etc/all.c"})
CreateAmalgamation(PREFIX.."lua.h", { "lua.h", "lauxlib.h", "lualib.h"})