lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Why exactly are you merging together the headers as well? That is for "ease of use" (which is questionable), not for speed, right?

For just getting the compiler optimizations, simply concatenating the .c's together would be enough? Roberto mentioned to have a Makefile target for this in upcoming versions, that would indeed be fine.

-asko


dcharno kirjoitti 15.2.2009 kello 19:49:

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"})