lua-users home
lua-l archive

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


> -----Original Message-----
> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
> Behalf Of Peng Zhicheng
> Sent: maandag 4 november 2013 16:42
> To: Lua mailing list
> Subject: Re: profiling problem

 
> Well, forget about it. I bet we both went the wong direction.
> 
> I ran that script from your original post this evening,
> just to find the result is slight different from yesterday's.
> 
> Then I added some unrelated code at the beginning. I say it
> unrelated because it just prints some text to the screen.
> 
> Surprisingly I found the result changed again. This time the
> execution time of the main loop and the "watched" coroutine
> became almost identical. Among several runs, the result showed
> some randomness - tha latter might be either slower or faster,
> but the average execution time diffence is near 0(and this is
> what I had expected at the very beginning).
> 
> More experiments showed that if I insert unrelated codes randomly,
> the results could all be affected in somewhat random manner.
> 
> You may try something similar to see whether it'll make some
> difference if you want.
> 
> So I suppose the diffence is not due to whether it is the main
> thread or a coroutine, nor to whether it is "watched"(hooked).
> As I stated earlier, the perfomance *should* have little difference
> as long as the debug hook is installed but not triggered,
> according to my understanding of the source code of Lua.

I did a check on that, by keeping a counter in a slightly modified corowatch version;

C:\Users\Thijs\Dropbox\Lua projects\corowatch\examples>performance.lua
Mainloop :      0.25116024017334
Coroutine:      0.23868064880371
Corowatch:      0.24492034912109        Debughook invokements:  1203
corowatch is 2% slower than unprotected
coroutine is 4% faster than the main loop

The debughook gets invoked 1203 times, so there should be an impact. In this version the watched coroutine consistenly is slightly (2% to 8%) slower than the non-watched version, which is expected, but differs for each experiment so far.

But the coroutine remains faster than the main loop, which I can't explain.
This would imply that any Lua program can get a 2-5% performance increase by simply wrapping it in a coroutine. Something like;

coroutine.resume(coroutine.wrap(function()
  <original code here>
end))

Thijs


> 
> Probably the diffence in the experiments was kind of butterfly effect,
> caused by some unknown, subtle factors. I don't know.