[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How can I optimize my metatables?
- From: "Soni \"They/Them\" L." <fakedme@...>
- Date: Fri, 1 Dec 2017 21:49:18 -0200
On 2017-12-01 01:45 AM, Meepen wrote:
Could you at all update metatables on coroutine switch? it'd be faster
if you used the metatables at all but would slow down minimally otherwise
Context switches instead of namespacing?
Hmm... Maybe. It wouldn't be easy, because with context switches, any
mistake leaks the wrong context. With namespacing, that problem is
pretty much non-existent.
I mean, what do modern CPUs and kernels use?
On Nov 30, 2017 6:17 PM, "Soni "They/Them" L." <firstname.lastname@example.org
I have some code that looks like this:
local mt = metatables[coroutine.running()].string
if mt then
local __index = rawget(mt, "__index")
if type(__index) == "function" then
It takes the metatables for the basic Lua types (string, number,
nil, etc) and replaces them with a proxy metatable. This proxy
metatable forwards to a different table based on the currently
running coroutine. This gives me virtualization of those metatables.
It's really slow (3-4x slower than the default string
metatable) and I'd like to make it faster. Is that possible?
 - I haven't actually benchmarked it, but default string
metatable gives about 2 table accesses per operation; this thing
does at least 8 when using globals, and that doesn't take into
account interpreter overhead and all the function calls!
Disclaimer: these emails may be made public at any given time,
with or without reason. If you don't agree with this, DO NOT REPLY.
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.