lua-users home
lua-l archive

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

On Wed, May 15, 2013 at 11:13:38PM -0700, William Ahern wrote:
> On Thu, May 16, 2013 at 12:30:23PM +0800, Dong Feng wrote:
> > Is there a keyword I could search in the mailing archive, to learn
> > more about the related discussion?
> > 
> > By the way, is it really so expensive that we have to avoid a
> > lua_checkstack() ? In this case, the call to lua_checkstack can be
> > made before GCTM(), outside the loop, to decrease the overhead of the
> > check. Is there justification to prefer an implicate assumption over
> > an explicit gurantee?
> > 
> It's not the cost of the function call so much as the cost of a conditional
> branch. The Lua VM very judicially uses similar tricks elsewhere to minimize
> conditional branching because it's one of the biggest--if not the
> biggest--cost factor with VMs on modern processors.

Also, it sounds a little bit like you're arguing for a belt+suspenders
approach to defensive programming. Some programmers might disagree with that
approach on principle, or in this particular context. There's no substitute
for understanding and following the contract when modifying internal code,
and there's no end to all the various assertions one could add in an attempt
to mitigate harm from a bug. In fact, lua_checkstack would hide bugs
regarding internal semantics.