[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: LuaJIT 2 clone-on-write for tables
- From: Alexander Gladysh <agladysh@...>
- Date: Wed, 19 Jan 2011 20:04:56 +0300
Hi, Mike, all!
This is a lazy question: I did not do my homework.
I use this function to clone my data tables ("tclone()"):
https://github.com/lua-nucleo/lua-nucleo/blob/master/lua-nucleo/table-utils.lua#L280-304
(It does not support circular references and does not copy metatables,
this is intentional.)
Now, I have a use case, where I traverse a data tree, calling
user-supplied hooks on each node. From hook return values I build the
new tree. The old tree should not be changed, and, most important, new
tree should not contain any links to the old tree tables.
I do traversal twice with different sets of hooks (second traversal is
done over the results of the first one).
If hook is missing, I tclone the original node. This is the most
frequent case — users usually supply hooks for limited number of data.
So, the question: is there a chance for LuaJIT 2 to somehow
automagically optimize out tclone() calls for the nodes that are never
changed?
If the answer is not "impossible", I will produce a minimal example to
demonstrate what is going on. (Also I should do some profiling to see
if the problem is as painful as I think — but then I should finish
writing the code first.)
Thanks,
Alexander.
P.S. I'm aware that I can code one kind or another of clone-on-write
in Lua, but if I have to do that, profiling comes first.