Fwd: Speed of control lookup (Was Re: Parent of Target)
    Mark Waddingham 
    mark at livecode.com
       
    Fri Aug 11 08:57:43 EDT 2017
    
    
  
On 2017-08-11 11:12, Mark Waddingham via use-livecode wrote:
> On 2017-08-10 21:10, Richard Gaskin via use-livecode wrote:
>> How might I measure the benefits of long ID caching?
Here is perhaps a better set of simple benchmarks to compare approaches 
to lookup (related to ids, anyway):
========
on mouseUp
    local tIterations
    put 100000 into tIterations
    -- card id is 1002
    -- button id is 1003
    -- group id is 1004
    local tLongId
    put the long id of button id 1003 of group id 1004 of card id 1002 
into tLongId
    local tButtonIdOfStack
    put "button id 1003 of stack" && quote & "LongIdSpeedTest" & quote 
into tButtonIdOfStack
    local tButtonIdOfCardIdOfStack
    put "button id 1003 of card id 1002 of stack" && quote & 
"LongIdSpeedTest" & quote into tButtonIdOfCardIdOfStack
    local tTime
    put the millisecs into tTime
    repeat tIterations times
       get the id of me
    end repeat
    put "Control" && (the millisecs - tTime) & return into msg
    put the millisecs into tTime
    repeat tIterations times
       get the id of tLongId
    end repeat
    put "GetIdOfLongIdInString" && (the millisecs - tTime) & return after 
msg
    put the millisecs into tTime
    repeat tIterations times
       get the id of tButtonIdOfCardIdOfStack
    end repeat
    put "GetIdOfButtonIdOfCardIdOfStackInString" && (the millisecs - 
tTime) & return after msg
    put the millisecs into tTime
    repeat tIterations times
       get the id of tButtonIdOfStack
    end repeat
    put "GetIdOfButtonIdOfStackInString" && (the millisecs - tTime) & 
return after msg
    put the millisecs into tTime
    repeat tIterations times
       get the id of button id 1003 of group id 1004 of card id 1002 of 
stack "LongIdSpeedTest"
    end repeat
    put "GetIdOfButtonIdOfGroupIdOfCardIdOfStack" && (the millisecs - 
tTime) & return after msg
    put the millisecs into tTime
    repeat tIterations times
       get the id of button id 1003 of card id 1002 of stack 
"LongIdSpeedTest"
    end repeat
    put "GetIdOfButtonIdOfCardIdOfStack" && (the millisecs - tTime) & 
return after msg
    local tStackString
    put "LongIdSpeed" & "Test" into tStackString
    put the millisecs into tTime
    repeat tIterations times
       get the id of button id 1003 of group id 1004 of card id 1002 of 
stack tStackString
    end repeat
    put "GetIdOfButtonIdOfGroupIdOfStackNotName" && (the millisecs - 
tTime) & return after msg
    put the millisecs into tTime
    repeat tIterations times
       get the id of button id 1003 of card id 1002 of stack tStackString
    end repeat
    put "GetIdOfButtonIdOfCardIdOfStackNotName" && (the millisecs - 
tTime) & return after msg
end mouseUp
========
On my machine (in 8.1.5) I get:
Control 21
GetIdOfLongIdInString 714
GetIdOfButtonIdOfCardIdOfStackInString 497
GetIdOfButtonIdOfStackInString 320
GetIdOfButtonIdOfGroupIdOfCardIdOfStack 56
GetIdOfButtonIdOfCardIdOfStack 53
GetIdOfButtonIdOfGroupIdOfStackNotName 65
GetIdOfButtonIdOfCardIdOfStackNotName 63
So, currently, there is a significant overhead to getting a control 
reference out of a string - the minimum you actually need in a string to 
uniquely identify a control (which may or may not have per-card data) is 
"control id ... of card id ... of stack ...".
Indeed - using the minimal info you need hard-coded in syntax:
       get the id of button id 1003 of card id 1002 of stack tStackString
Is about 10 times faster than using a long id in a string and about 8 
times faster than using a modified form of a string id to cut out the 
(strictly) unnecessary bits:
       get the id of "button id 1003 of card id 1002 of stack 
LongIdSpeedTest" -- quoted name, appropriately
So, my advice changes *slightly* - if you are doing tight loops which 
need to manipulate lots of controls in the current card of the 
defaultStack use:
       control id <id>
If the things aren't on the current card of the default stack, then 
extract the card id and stack name outside of the loop and use:
       control id <id> of card id tCardId of stack tStackName
The question of course is 'how fast could we get long id parsing to be' 
(as that is the bottleneck here, or at least appears to be).
Warmest Regards,
Mark.
P.S. Due to a mailing server glitch any mails which were sent here 
between 12:30BST and 14:00BST will not have got through.
-- 
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps
    
    
More information about the use-livecode
mailing list