[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Share proto object among multiple lua vm
- From: 云风 <cloudwu@...>
- Date: Thu, 20 Mar 2014 12:25:35 +0800
There are many lua vm (more then 10K) in one process in our system. We
run all of them by a thread pool. It runs well except huge memory
usage , because the same byte codes exist in each vm .
So I make a patch to lua 5.2.3 to share the same Proto objects among
multiple lua vm .
It introduces a new api : void lua_clonefunction (lua_State *L, const void * fp)
We can get a lua function's pointer by lua_topointer first, and then
pass it to lua_clonefunction to generate a new lua closure. The origin
lua function can be in different lua vm .
So we can put all the functions need to be share in an independent lua
vm , and share them to other lua vm in the same process.
It can also accelerate the vm's bootstrap , because no parser or
undump needed .