Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tl;dr: abc:func() = less opcodes, but slightly slower (due to metatable lookup in C),
- meta.func(abc) = 1 or 2 more opcodes, depending on Lua 5.1 or 5.2, but executes quicker
- as no need to lookup the metatable.
- (10:29:37) Kobra: infact
- (10:29:39) Kobra: ima test
- (10:29:39) Sykranos: like my bonepos func? its gonna give me the edge in hvh
- (10:29:39) Kobra: wait
- (10:30:04) Sykranos: was gonna do a full out bonescan
- (10:30:06) Sykranos: but too laggy
- (10:35:48) Kobra: rofl
- (10:35:51) Kobra: you're not gona belive this
- (10:35:54) Sykranos: wot
- (10:36:01) Kobra: test:func("world")
- (10:36:03) Kobra: uses less opcodes
- (10:36:04) Kobra: than
- (10:36:10) Kobra: meta.func(test, "world")
- (10:36:18) Sykranos: :O
- (10:36:20) Kobra: function <test.lua:15,18> (6 instructions at 0xf0be20)
- 0 params, 4 slots, 1 upvalue, 1 local, 3 constants, 0 functions
- 1 [16] GETTABUP 0 0 -1 ; _ENV "new"
- 2 [16] CALL 0 1 2
- 3 [17] SELF 1 0 -2 ; "func"
- 4 [17] LOADK 3 -3 ; "world"
- 5 [17] CALL 1 3 1
- 6 [18] RETURN 0 1
- function <test.lua:20,23> (7 instructions at 0xf0b780)
- 0 params, 4 slots, 2 upvalues, 1 local, 3 constants, 0 functions
- 1 [21] GETTABUP 0 0 -1 ; _ENV "new"
- 2 [21] CALL 0 1 2
- 3 [22] GETTABUP 1 1 -2 ; meta "func"
- 4 [22] MOVE 2 0
- 5 [22] LOADK 3 -3 ; "world"
- 6 [22] CALL 1 3 1
- 7 [23] RETURN 0 1
- (10:36:28) Kobra: top one is test:func()
- (10:36:33) Sykranos: so
- (10:36:38) Sykranos: i should be doinn
- (10:36:47) Sykranos: local alive = _R.Player.Alive
- (10:36:48) Sykranos: ?
- (10:37:03) Kobra: no
- (10:37:07) Kobra: ply:Alive()
- (10:37:12) Sykranos: but
- (10:37:14) Sykranos: muh local copy
- (10:37:15) Kobra: no metatable
- (10:37:18) Kobra: srsly
- (10:37:19) Kobra: it's quicker
- (10:37:20) Kobra: lol
- (10:37:24) Sykranos: okay
- (10:38:02) Kobra: lol
- (10:38:05) Kobra: that's halarious
- (10:38:09) Kobra: i thought it was quicker
- (10:38:34) Kobra: wait
- (10:38:36) Kobra: gmod uses
- (10:38:37) Kobra: lua 5.1
- (10:38:48) Sykranos: so is what im doing quicker or not
- (10:38:49) Kobra: oh my
- (10:38:50) Kobra: HAHAHA
- (10:38:56) Kobra: function <test.lua:15,18> (6 instructions, 24 bytes at 0x2035460)
- 0 params, 4 slots, 0 upvalues, 1 local, 3 constants, 0 functions
- 1 [16] GETGLOBAL 0 -1 ; new
- 2 [16] CALL 0 1 2
- 3 [17] SELF 1 0 -2 ; "func"
- 4 [17] LOADK 3 -3 ; "world"
- 5 [17] CALL 1 3 1
- 6 [18] RETURN 0 1
- function <test.lua:20,23> (8 instructions, 32 bytes at 0x2034830)
- 0 params, 4 slots, 1 upvalue, 1 local, 3 constants, 0 functions
- 1 [21] GETGLOBAL 0 -1 ; new
- 2 [21] CALL 0 1 2
- 3 [22] GETUPVAL 1 0 ; meta
- 4 [22] GETTABLE 1 1 -2 ; "func"
- 5 [22] MOVE 2 0
- 6 [22] LOADK 3 -3 ; "world"
- 7 [22] CALL 1 3 1
- 8 [23] RETURN 0 1
- (10:39:01) Kobra: lua 5.1 is even SLOWER
- (10:39:07) Kobra: doing the manuyal meta way
- (10:39:15) Kobra: 2 instructions more
- (10:39:45) Kobra: in lua 5.2
- (10:39:46) Kobra: 3 [22] GETUPVAL 1 0 ; meta
- 4 [22] GETTABLE 1 1 -2 ; "func"
- (10:39:52) Kobra: ins converted into 1 opcode
- (10:39:55) Kobra: that's the difference
- (10:40:02) Kobra: 3 [22] GETTABUP 1 1 -2 ; meta "func"
- (10:40:14) Sykranos: muh local copies
- (10:41:03) Kobra: wait
- (10:41:09) Kobra: im going to test
- (10:41:10) Sykranos: you know what would be cool?
- (10:41:13) Kobra: by having empty func
- (10:41:15) Sykranos: lua bindings to C for trace arrays
- (10:41:23) Sykranos: then an auto wall would be feasible
- (10:41:39) Sykranos: so would a bonescan
- (10:41:54) Kobra: 3 [22] GETTABUP 1 1 -2 ; meta "func"
- 4 [22] MOVE 2 0
- 5 [22] LOADK 3 -3 ; "world"
- 6 [22] CALL 1 3 1
- 7 [23] RETURN 0 1
- (10:41:59) Kobra: = manual meta way
- (10:42:04) Kobra: those are the relevant opcodes
- (10:42:21) Kobra: this is
- (10:42:27) Kobra: meta way
- (10:42:28) Kobra: 3 [17] SELF 1 0 -2 ; "func"
- 4 [17] LOADK 3 -3 ; "world"
- 5 [17] CALL 1 3 1
- (10:42:38) Sykranos: its too early in the morning for this
- (10:42:43) Sykranos: WHICH 1 IS FASTER?!
- (10:42:56) Kobra: _R.Player.Alive(pl) is slower
- (10:43:01) Kobra: pl:Alive() is faster
- (10:43:52) Kobra: eh
- (10:43:54) Kobra: so you can see
- (10:43:57) Kobra: this will make more sense
- (10:43:58) Kobra: function a()
- local test = new()
- test:func("world")
- end
- function b()
- local test = new()
- meta.func(test, "world")
- end
- function c()
- local test = new()
- end
- (10:44:09) Kobra: function <test.lua:15,18> (6 instructions at 0x1ee1e20)
- 0 params, 4 slots, 1 upvalue, 1 local, 3 constants, 0 functions
- 1 [16] GETTABUP 0 0 -1 ; _ENV "new"
- 2 [16] CALL 0 1 2
- 3 [17] SELF 1 0 -2 ; "func"
- 4 [17] LOADK 3 -3 ; "world"
- 5 [17] CALL 1 3 1
- 6 [18] RETURN 0 1
- function <test.lua:20,23> (7 instructions at 0x1ee1780)
- 0 params, 4 slots, 2 upvalues, 1 local, 3 constants, 0 functions
- 1 [21] GETTABUP 0 0 -1 ; _ENV "new"
- 2 [21] CALL 0 1 2
- 3 [22] GETTABUP 1 1 -2 ; meta "func"
- 4 [22] MOVE 2 0
- 5 [22] LOADK 3 -3 ; "world"
- 6 [22] CALL 1 3 1
- 7 [23] RETURN 0 1
- function <test.lua:25,27> (3 instructions at 0x1ee2950)
- 0 params, 2 slots, 1 upvalue, 1 local, 1 constant, 0 functions
- 1 [26] GETTABUP 0 0 -1 ; _ENV "new"
- 2 [26] CALL 0 1 2
- 3 [27] RETURN 0 1
- (10:45:15) Sykranos: ALRIGHT
- (10:45:20) Kobra: hmmm, maybe the metamethods being called
- (10:45:25) Kobra: slows it down?
- (10:45:30) Kobra: idk
- (10:45:33) Kobra: ill test
- (10:45:39) Kobra: via bruiteforce
- (10:48:33) Sykranos: what if i used rawget to access it
- (10:49:06) Kobra: well
- (10:49:11) Kobra: then you're calling rawget
- (10:49:21) Sykranos: but not calling _newindex
- (10:50:00) Kobra: yeah, but your replacing the __index call (newindex is setting) with the rawget
- (10:50:06) Kobra: the __index call isn't done either
- (10:50:11) Kobra: it's only done IF there is a metatable
- (10:50:18) Sykranos: dig bicks
- (10:50:22) Kobra: and that check is done in C
- (10:50:24) Kobra: a 22.514733076096
- b 21.983674049377
- (10:50:30) Kobra: so, even tho it's more opcodes
- (10:50:33) Kobra: it's quicker
- (10:50:44) Kobra: i presume the metatable lookup is slightly slower
- (10:50:50) Kobra: but, it's so negligable
- (10:51:02) Kobra: i'd keep the erm
- (10:51:09) Kobra: abc:def()
- (10:51:12) Kobra: for reduced bugs
- (10:51:15) Kobra: simpler code
- (10:51:18) Kobra: and easier to maintain
- (10:51:20) Kobra: and read
- (10:51:26) Sykranos: wudeva
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement