lua-users home
lua-l archive

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


Alex Bradbury wrote:
> When writing this code initially, I had hoped that LuaJIT would just
> inline check_mem_alignment and check_mem_range. But with the standard
> heuristics the presence of these calls means it fails to generate any
> acceptable traces, as far as I can see due to 'too many snapshots'.

It does inline the check (not the full body, only the fast path).
But the check is a Lua conditional and every explicit conditional
also creates a new snapshot (actually two, one before and one
after the condition).

If you can turn these checks into constant expressions, this won't
happen. E.g. replace cpu.memsize with 65536 (or whatever), then if
addr is a constant the whole check can be eliminated. Use runtime
code generation to specialize the checks to their constant values.

This does assume that e.g. addr is a constant, but I think you can
guarantee this in many cases.

> To give an idea of what a massive difference this makes, consider the
> following numbers from my test program (the simulated code is a naive
> fibonacci implementation). Using my prototype codegen and including
> the check_mem calls it takes ~2 minutes to run. Just adding
> -Omaxsnap=200 (up from the default 100) results in a drastically
> reduced 1.1-1.4 second runtime. Commenting out the calls results in ~1
> second runtime with default parameters.

Ok, maybe the default value of maxsnap is a bit conservative. Hmmm ...

--Mike