Alex Tweedly wrote:
On 30/10/2014 18:36, Richard Gaskin wrote:
1. ID caching
Page 10 of the v6.0 Release Notes:
<http://downloads.livecode.com/livecode/6_0_0/LiveCodeNotes-6_0_0.pdf>
The description there says:
The engine now caches lookups of control references of the form
“card id ...” and “control id ...”. This speeds up any access
using those forms after the first time, turning an operation that
would be completed in linear time into one that will be completed
in constant time.
What does that mean in practical terms? How can I benchmark the
benefit of this new feature?
Hmmmm - I said this once before :-) :-)
My apologies for the inconvenience. I'd either missed it before or
completely forgot about it, but the latter seems unlikely given how
remarkable the post was:
Yes, here's an example. The clue (I think) is in the "linear
time...into constant time"
Create a large-ish number of controls - in this stack I cloned a
button 1000 times, calling them
BBB1 BBB2 .... BBB1000
Then this code accesses a single control many times - and shows that
accessing by id is much faster than accessing by name, but more
importantly here, that in 6.0 access by id to the most recently
accessed control is very fast.
in 5.5.3
name takes 830 ms while id takes only 250 ms
but in 6.0 (i.e. with id caching)
name takes 830 ms while id takes 5 ms
-- Alex.
global K
on mouseUp
put 1000 into K
put the millisecs into t1
put "BBB"&(K-10) into tName
repeat 10000 times
put the short name of control tName into t
end repeat
put the millisecs-t1 && t &CR after msg
put the millisecs into t1
put the id of button tName into tID
repeat 10000 times
put the short name of control id tID into t
end repeat
put the millisecs-t1 && t &CR after msg
end mouseUp
What I find most remarkable is the way your benchmark makes the value of
this ID caching seem rather trivial.
I trust this was a one-liner, as I can't imagine them spending much time
optimizing something so very specialized and which takes so little
execution time per iteration.
I wonder what prompted this one...perhaps something specific to the
coding style of the person who wrote the Project Browser?
--
Richard Gaskin
Fourth World Systems
Software Design and Development for Desktop, Mobile, and Web
____________________________________________________________
ambassa...@fourthworld.com http://www.FourthWorld.com
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode