Work In Progress: About Lua Structures

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Work In Progress: About Lua Structures

Ranier Vilela-2
Hi,

Work In Progress: About Lua structures
Sizeofs 64 bits (msvc 2019 64 bits):
Instruction: 4
TValue: 16
TString: 32
LClosure: 40
Proto: 128

I'm studying the structures of Lua, and one caught my attention: struct Proto

I think it's breaking the cache line in two.
After running the factorial test (https://github.com/GitSparTV/lua-infographics/blob/main/lua-benchmark/benchmark.lua)

An information caught my attention:
0.03s trap = L-> hookmask;
returning: / * trap already set * /
0.04s cl = clLvalue (s2v (cy-> func));
0.13s k = cl-> p-> k;
0.01s pc = cy-> u.l.savedpc;
0.01s if (trap) {

A simple move is taking an average of 0.15s (0.13s to 0.15s).
0.13s k = cl->p->k;

Wouldn't Lua benefit from dividing struct Proto in two?
Would it pay off?

regards,
Ranier Vilela
Reply | Threaded
Open this post in threaded view
|

Re: Work In Progress: About Lua Structures

Spar
Hi. The link just go down, here is working link for sure: https://github.com/GitSparTV/lua-infographics/tree/main/lua-benchmark/

Sharing my knowledge.
I was learning LuaJIT bytecode some time ago, and discovered that for 64bit versions the TValue struct is actually shared between 2 TValues objects.
As assume this is done for pointer/RAM optimizations.
However, for the same reason LuaJIT had to make 2 versions of bytecode: regular (32 bit) and with FR2 (Frame Size 2). 64-bit bytecode is not compatible with 32-bit executable and the opposite.
Devs said they might add compatibility between them later, but this did not happen yet.

One of the LuaJIT devs (corsix) did a talk about FR2 in 2017: https://www.youtube.com/watch?v=ZeaDk9ElKws
He also discussed it here: https://github.com/LuaJIT/LuaJIT/issues/209 

I don't have enough knowledge and experience in this field to say if that's a benefit, so I just shared some information I know.


On Fri, Nov 13, 2020 at 1:38 AM Ranier Vilela <[hidden email]> wrote:
Hi,

Work In Progress: About Lua structures
Sizeofs 64 bits (msvc 2019 64 bits):
Instruction: 4
TValue: 16
TString: 32
LClosure: 40
Proto: 128

I'm studying the structures of Lua, and one caught my attention: struct Proto

I think it's breaking the cache line in two.
After running the factorial test (https://github.com/GitSparTV/lua-infographics/blob/main/lua-benchmark/benchmark.lua)

An information caught my attention:
0.03s trap = L-> hookmask;
returning: / * trap already set * /
0.04s cl = clLvalue (s2v (cy-> func));
0.13s k = cl-> p-> k;
0.01s pc = cy-> u.l.savedpc;
0.01s if (trap) {

A simple move is taking an average of 0.15s (0.13s to 0.15s).
0.13s k = cl->p->k;

Wouldn't Lua benefit from dividing struct Proto in two?
Would it pay off?

regards,
Ranier Vilela
Reply | Threaded
Open this post in threaded view
|

Re: Work In Progress: About Lua Structures

Ranier Vilela-2
Em qui., 12 de nov. de 2020 às 21:00, Spar <[hidden email]> escreveu:
Hi. The link just go down, here is working link for sure: https://github.com/GitSparTV/lua-infographics/tree/main/lua-benchmark/

Sharing my knowledge.
I was learning LuaJIT bytecode some time ago, and discovered that for 64bit versions the TValue struct is actually shared between 2 TValues objects.
As assume this is done for pointer/RAM optimizations.
I don't think TValue is a problem, in 64 bits the size of the structure is 16.

regards,
Ranier Vilela
Reply | Threaded
Open this post in threaded view
|

Re: Work In Progress: About Lua Structures

Spar
I mean in LuaJIT it's TValue, but in Lua it's probably Proto that needs split

On Fri, Nov 13, 2020 at 4:52 AM Ranier Vilela <[hidden email]> wrote:
Em qui., 12 de nov. de 2020 às 21:00, Spar <[hidden email]> escreveu:
Hi. The link just go down, here is working link for sure: https://github.com/GitSparTV/lua-infographics/tree/main/lua-benchmark/

Sharing my knowledge.
I was learning LuaJIT bytecode some time ago, and discovered that for 64bit versions the TValue struct is actually shared between 2 TValues objects.
As assume this is done for pointer/RAM optimizations.
I don't think TValue is a problem, in 64 bits the size of the structure is 16.

regards,
Ranier Vilela