[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Running BoundsChecker on 5.0.2
- From: Mike Pall <mikelu-0602@...>
- Date: Sun, 26 Feb 2006 15:02:01 +0100
Michael Abbott wrote:
> Just for interest sake, how much memory of this type is getting copied
Very often. Assignments, function calls and returns are the most
common causes. Just look for the setobj (and variant) macros in
> I would have though that copying around data that just gets
> overwritten again / never used would have been a bad sign (from an
> efficiency standpoint)?
Not really. Copying a TObject (TValue in Lua 5.1) struct is
cheap. This is 3 loads and 3 stores on a 32 bit platform (with
lua_Number = double). Most of it is in the L1 D-cache. Reordering
is easy because there are no data dependencies.
The alternative would be a switch statement which copies only the
needed parts depending on the type. This takes between 1-3 loads
and 1-3 stores. But it includes one unpredictable branch and several
instructions for range checking and computing the branch target.
And branches to join the control flow, too.
The unpredictable branch alone is worth between 10-20 cycles on
recent x86 CPUs. This is more than the whole struct copy. And the
I-cache would be hit really hard if you inlined all of this. Also
reordering is more difficult. Summary: this would be dead slow.
More info about optimizing code for modern CPU architectures: