[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Potential performance improvements for Lua 5.2 beta
- From: Joshua Jensen <josh.jjensen@...>
- Date: Wed, 03 Aug 2011 23:59:13 -0600
In several custom (mostly numeric) benchmarks, Lua 5.1 has been
performing much better than Lua 5.2 beta, so I've been playing around
with improving performance in Lua 5.2 beta under Visual Studio 2010. My
experimentation can be found at
https://github.com/jjensen/lua52/tree/performance-improvements.
First, on my Core i7 720 laptop, turning off #define MS_ASMTRICK saves a
bit of time.
I also turned off LUA_NANTRICKLE to bring it closer to Lua 5.1's
performance and give a more head to head comparison.
Okay, with those out of the way, I hit lvm.c. For my particular
benchmarks, the VM executes luaV_lessthan() and luaV_lessequal() a lot.
Adopting the Lua 5.1 type equality check helps out considerably.
int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
int res;
if (ttype(l) == ttype(r)) {
if (ttisnumber(l))
return luai_numlt(L, nvalue(l), nvalue(r));
else if (ttisstring(l))
return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
}
else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
return res;
return luaG_ordererror(L, l, r);
}
int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {
int res;
if (ttype(l) == ttype(r)) {
if (ttisnumber(l))
return luai_numle(L, nvalue(l), nvalue(r));
else if (ttisstring(l))
return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
}
else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try
`le' */
return res;
else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */
return !res;
return luaG_ordererror(L, l, r);
}
The other change involves altering the usages of ci->u.l.savedpc. The
first alteration made involves using a pointer to ci->u.l.savedpc
(Instruction **pc) and dereferencing the PC through there. This helps,
but I wondered if I could get even closer to the Lua 5.1 code.
I then used an Instruction *pc and tried to update ci->u.l.savedpc at
key intervals. I did this quickly. It might be wrong, but the
performance improvement was huge.
The c->u.l.savedpc changes are large enough that I refer you to the
GitHub URL.
After these changes, 2 of the 3 benchmarks now performed better in Lua
5.2 than under Lua 5.1.
Just one final note... the vmdispatch() and vmcase() macros make the VM
a pain to debug under Visual Studio 2010. I had to spend the bulk of my
time in the assembly view trying to match instructions up to lines of code.
Thanks.
Josh