[Tile-serving] [openstreetmap/osm2pgsql] Using LuaJIT to speed up lua code (#801)
mmd
notifications at github.com
Sat Nov 18 21:24:23 UTC 2017
LuaJIT provides a nice plugin replacement mechanism to run Lua code with JIT optimizations: http://luajit.org/luajit.html.
I did some very quick & dirty prototyping to have at least a working osm2pgsql, and compared run times on a small county extract w/ and w/o LuaJIT.
Before (Lua)
Processing: Node(3045k 1015.2k/s) Way(556k 46.37k/s) Relation(1790 1790.00/s) parse time: 16s
After (LuaJIT)
Processing: Node(3045k 3045.5k/s) Way(556k 139.12k/s) Relation(3410 3410.00/s) parse time: 6s
So it seems this might be interesting to be investigated in more detail.
CMake code: https://github.com/ranisalt/forgottenserver/blob/luajit-optional/cmake/FindLuaJIT.cmake
```C++
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0b62652..99887ad 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -85,7 +85,8 @@ find_package(Osmium REQUIRED COMPONENTS io proj)
include_directories(SYSTEM ${OSMIUM_INCLUDE_DIRS})
if (WITH_LUA)
- find_package(Lua REQUIRED)
+# find_package(Lua REQUIRED)
+ find_package(LuaJIT REQUIRED)
include_directories(${LUA_INCLUDE_DIR})
set(HAVE_LUA 1)
endif()
@@ -108,7 +109,7 @@ find_package(Threads)
set (LIBS ${Boost_LIBRARIES} ${PostgreSQL_LIBRARY} ${OSMIUM_LIBRARIES})
-if (LUA_FOUND)
+if (LUA_FOUND OR LUAJIT_FOUND)
list(APPEND LIBS ${LUA_LIBRARIES})
endif()
@@ -212,7 +213,7 @@ set(osm2pgsql_lib_SOURCES
wkb.hpp
)
-if (LUA_FOUND)
+if (LUA_FOUND OR LUAJIT_FOUND)
list(APPEND osm2pgsql_lib_SOURCES tagtransform-lua.cpp)
endif()
diff --git a/tagtransform-lua.cpp b/tagtransform-lua.cpp
index cf9021b..a17ed54 100644
--- a/tagtransform-lua.cpp
+++ b/tagtransform-lua.cpp
@@ -19,6 +19,9 @@ lua_tagtransform_t::lua_tagtransform_t(options_t const *options)
m_extra_attributes(options->extra_attributes)
{
luaL_openlibs(L);
+ luaJIT_setmode(L, -1, LUAJIT_MODE_WRAPCFUNC|LUAJIT_MODE_ON);
+ lua_pop(L, 1);
+
luaL_dofile(L, options->tag_transform_script->c_str());
check_lua_function_exists(m_node_func);
diff --git a/tagtransform-lua.hpp b/tagtransform-lua.hpp
index 0d951ac..de78cd6 100644
--- a/tagtransform-lua.hpp
+++ b/tagtransform-lua.hpp
@@ -6,9 +6,10 @@
#include "tagtransform.hpp"
extern "C" {
-#include <lua.h>
+#include "luajit.h"
}
+
class lua_tagtransform_t : public tagtransform_t
{
public:
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/osm2pgsql/issues/801
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/tile-serving/attachments/20171118/0e95b8c2/attachment.html>
More information about the Tile-serving
mailing list