lua-users home
lua-l archive

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


I test the "lua-5.4.0-alpha-rc2" recently, and found that the 'forloop' is more faster than 'lua5.3'。

The test code is that:
`
collectgarbage("stop")
local function foo()
     local a = 3
     for i = 1, 64 * 1024 * 1024 do
         a = i
     end
     print(a)
end
foo()
`

In the end, I found that a magic modification(https://github.com/lua/lua/commit/4bb30f461b146e1d189ee301472953e948699acf) by Roberto can greatly improve the efficiency of 'setobj'(a=i).

The modification is as follows:

`
     #define setobj(L,obj1,obj2) \
-    { TValue *io1=(obj1); *io1 = *(obj2); \
+    { TValue *io1=(obj1); const TValue *io2=(obj2); \
+         io1->value_ = io2->value_; io1->tt_ = io2->tt_; \
           (void)L; checkliveness(L,io1); }

`

I disassembled this change, and can't find the key point.

So, who can't point me the key? Thank you very much.

Sorry for my bad English.