lua-users home
lua-l archive

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


It was thus said that the Great Coroutines once stated:
> On Fri, Apr 4, 2014 at 5:34 PM, Sean Conner <sean@conman.org> wrote:
> 
> >   How do you know that marshalling is the slowest way?  You are making that
> > assumption (QNX X server marshalls, and it's faster than using shared
> > memory).  It may also be that you are trying to share too much thus causing
> > cache contention [1].
> >
> >   -spc (The only way to be sure is to measure ... )
> >
> > [1]     A novel new approach to spinlocks:
> >
> >                 http://lwn.net/Articles/590243/
> >
> >         It uses way more memory than a traditional spinlock (something like
> >         2*number-cpus) but in practical real-world tests [2] it was 100%
> >         faster, *because* it reduced cache contention.
> >
> > [2]     A particular type of benchmark *cough cough*.
> >
> Hmm, well you were right to question my assumptions, I have not done
> benchmarks -- I just imagined marshalling usually to be converting a table
> of lua values to a string, which would always seem slower than if I could
> memcpy a set of Lua objects to load in to this separate global_State
> (theoretically).  Is there a better way (than object -> string marshalling)?

  If the two Lua states are in the same process, you can certainly skip the
object->string->object routine and just copy the values over:

	lua_createtable(L2,0,0);

	lua_pushnil(L1);
	while (lua_next(L1,t) != 0)
	{
          switch(L1,lua_type(L,-2))
	  {
 	    case LUA_TNUMBER: lua_pushnumber(L2,lua_tonumber(L1,-2)); break;
	    /* ... */
	  }
	  switch(L1,lua_type(L,-1))
	  {
	    case LUA_TNUMBER: lua_pushnumber(L2,lua_tonumber(L1,-1)); break;
	    /* ... */
	  }
	  lua_settable(L2,-3);
	}

But if it's process->process (or even across the network) then yes, you'll
need some form of marshalling code [3].

  -spc (Again, if you are trying to do this for arbitrary objects, I still
	think you are doing it wrong ... )

[3]	I just realized why the message copying of QNX might have been so
	fast---it only ever ran on the Intel platform, so it could ignore
	byte endian issues.  And programmers were warned not to pass raw
	pointers since that would be meaningless.  It could sidestep a whole
	bunch of issues.