lua-users home
lua-l archive

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




2018-03-17 17:56 GMT+01:00 Dibyendu Majumdar <mobile@majumdar.org.uk>:
On 17 March 2018 at 14:53, Rodrigo Azevedo <rodrigoams@gmail.com> wrote:

>
> Question: Why the incremental Lua 5.4 performs better (CPU TIME) than Lua
> 5.2 or 5.3? My guess is the new VM instructions (what are the new ones?), am
> I right? or some optimization of the incremental gc? anything else?
>

Lua 5.4 has several optimizations for bytecodes that is used in
numeric programs - load, indexing, arithmetic ops codes, for num
opcodes etc. are specialized for situations where the parser can
detect numeric constants and infer types. For instance now there are
GETI/SETI opcodes for extracting/updating values table values where
the index key is an integer. The VM also has optimizations such as
avoiding operations not needed or minimizing the impact of those. The
net result is improved performance which is very welcome.



I could confirm that new opcodes speedup Lua

    $ lua-5.3.4/src/lua harness.lua NBody 7 250000
    Starting NBody benchmark ...
    NBody: iterations=1 runtime: 1207250us
    NBody: iterations=1 runtime: 1194877us
    NBody: iterations=1 runtime: 1188912us
    NBody: iterations=1 runtime: 1205081us
    NBody: iterations=1 runtime: 1203040us
    NBody: iterations=1 runtime: 1216759us
    NBody: iterations=1 runtime: 1210723us
    NBody: iterations=7 average: 1203806us total: 8426642us

    Total Runtime: 8426642us
    $ lua-5.4.0-work1/src/lua harness.lua NBody 7 250000
    Starting NBody benchmark ...
    NBody: iterations=1 runtime: 1024333us
    NBody: iterations=1 runtime: 1013502us
    NBody: iterations=1 runtime: 1014108us
    NBody: iterations=1 runtime: 1013805us
    NBody: iterations=1 runtime: 1012738us
    NBody: iterations=1 runtime: 1013662us
    NBody: iterations=1 runtime: 1019850us
    NBody: iterations=7 average: 1016000us total: 7111998us

    Total Runtime: 7111998us

    $ lua-5.3.4/src/lua -lluasom harness.lua CD 7 1000
    Starting CD benchmark ...
    CD: iterations=1 runtime: 8708780us
    CD: iterations=1 runtime: 9199042us
    CD: iterations=1 runtime: 9239055us
    CD: iterations=1 runtime: 9219889us
    CD: iterations=1 runtime: 9175078us
    CD: iterations=1 runtime: 9289253us
    CD: iterations=1 runtime: 9343105us
    CD: iterations=7 average: 9167743us total: 64174202us

    Total Runtime: 64174202us
    $ lua-5.4.0-work1/src/lua -lluasom harness.lua CD 7 1000
    Starting CD benchmark ...
    CD: iterations=1 runtime: 6767993us
    CD: iterations=1 runtime: 6934665us
    CD: iterations=1 runtime: 6657718us
    CD: iterations=1 runtime: 6816613us
    CD: iterations=1 runtime: 7016126us
    CD: iterations=1 runtime: 6617097us
    CD: iterations=1 runtime: 6846714us
    CD: iterations=7 average: 6808132us total: 47656926us

    Total Runtime: 47656926us

18% faster for NBody
34% faster for CD

These scripts (with some others) are available on https://github.com/fperrad/are-we-fast-yet/tree/alt_lua/benchmarks/Lua
I run them on GNU/Linux Debian 9 x86_64
I built vanilla lua (+ luasocket) with gcc 6.3.0

François