lua-users home
lua-l archive

Re: [Patch] Finalization of function objects

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


On 2008年1月28日 14:22:42 +0500
"Nodir Temirhodzhaev" <nodir.temir@gmail.com> wrote:
> Some optimizations, bug fixes and finally() parameters changed.
> 
> Thanks to Thomas Harning for report about glitches.
> 
> Patch for Lua 5.1.3:
> http://lua-users.org/files/wiki_insecure/users/tnodir/lua-5.1.3-finpatch.tar.gz
I've tested this new patch and it seems to work pretty good.
It appears that all that's needed is some more error checking in the
finalization and/or finally code to avoid PANIC's from occuring.
It may also be important to work out how errors are managed inside
finalizers....
I also figured another useful test for the finalizer 'speed' test. An
'ensured' one in which a pcall is used to ensure that a destructor of
sorts is called.
In my performance test I noticed the following specs w/ the patched
performance test I sent:
Finally	0.46
Direct	0.33
Ensured	0.44
(Tests performed on AMD Athlon(tm) 64 X2 Dual Core Processor 6000+
[64-bit compiled]
... 32-bit compiled didn't make a difference in these tests
 Looks like perhaps a little performance enhancements
could bring finally to be faster than pcall method. It's kind of an odd
result I might add... woulda thought the C-stack preservations that
pcall did would cause a larger hit.
Even increasing the iterations didn't change the ratios.
One thing I thought of... i bet it would be faster than pcall if the
stack depth were deeper.... [did a quick test in which the stack depth
were artificially deepened using a non-tail-recursive loop and it had
minimal effect (just evening out the results due to less % work by each
method)...]
Pattern:
do
	finally(doFinally)
	work()
end
=>
local status, ret = pcall(function()
	work()
end)
doFinally()
if not status then error(ret, 0) end
--- /home/harningt/lua-5.1.3-finpatch/speed.lua	2008年01月28日 03:28:15.000000000 -0500
+++ lua-5.1.3-finpatch/speed.lua	2008年03月05日 00:26:23.000000000 -0500
@@ -19,6 +19,7 @@
 do
 	local function foo(i)
 		finally(add, i)
+		add(i)
 	end
 
 	measure(foo, "Finally")
@@ -28,7 +29,18 @@
 do
 	local function foo(i)
 		add(i)
+		add(i)
 	end
 
 	measure(foo, "Direct")
 end
+-- Ensured
+do
+	local function foo(i)
+		pcall(add, i)
+		add(i)
+	end
+
+	measure(foo, "Ensured")
+end
+

AltStyle によって変換されたページ (->オリジナル) /