Using [ Control "SomeImageName" ] VS [image "SomeImageName"]

Ali Lloyd ali.lloyd at livecode.com
Tue Feb 2 04:51:26 EST 2016


Yes, in general specifying the control type when referring to the control
by name will be very slightly faster than not doing so - this is because
when cycling through the controls of a card to see if there is a match, a
non-matching control type can be instantly disregarded (a constant time
operation).

When using

control "SomeImageName"

the engine will have to check the name against the names of each control on
the card until it finds a match. In theory name checking is also constant
time, however because we allow somewhat fuzzy chunk expressions that is not
quite true in practice. E.g.

local tVar

put the name of button 1 into tVar

put the long id of button tVar

will work. For that to work, our name matching function has to find the
offset of the first and next quote (if they exist), and compare substrings
caselessly. In the worst case scenario, you might have a million buttons
and one image all named

"SomeExtremelyLongString<lots more characters>Button1",
...
"SomeExtremelyLongString<lots more characters>Button100000",
"SomeExtremelyLongString<lots more characters>Image"

It would turn out to much quicker to specify image rather than use control.

Controls referenced by id are cached, so on a stack / card with many
controls especially of the same type, it will usually be better to
reference a control by id (and then it is irrelevant whether you specify
the type or not).

On Tue, Feb 2, 2016 at 4:51 AM Sannyasin Brahmanathaswami <brahma at hindu.org>
wrote:

> I using some scripts lately where it seems convenient to do something like
> this:
>
>
>
> global gCurrentHiddenControl, gCurrentShowingControl
>
>
> # then:
>
>
> command fadeOutCurrentControl pSpeed
>
>    put (the blendlevel of control gCurrentShowingControl) +1 into tLevel
>
>    set the blendlevel of control gCurrentShowingControl to tLevel
>
>    if tLevel < 100 then
>
>       send fadeOutCurrentControl to this stack in pSpeed ticks
>
>    else
>
>      lastRevealDone
>
>    end if
>
> end fadeOutCurrentControl
>
>
> # OR (testing which is better… send in time or repeat loops
>
>
> command revealWithBlendLevel, pSpeed,pIterations
>
>    repeat pIterations times
>
>       set the blendlevel of  control gCurrentHiddenControl to pIterations
>
>       subtract 1 from pIterations
>
>       wait pSpeed milliseconds
>
>    end repeat
>
> end revealWithBlendLevel
>
>
> How much of hit on the processing time are we inducing by not specify the
> control type? Is it a trivial amount of extra time?  or is it seriously
> impacting performance… One never knows.
>
> OTOH… Seeing Animation Engine’s method  which uses the long ID *AND* a
> specific control declaration.
>
>
>  aeChangeRect the long ID of  img "stage-1_layer-1",
> tNewLocation,tMove1Speed,”out”
>
>
> makes me wonder if using
>
>
> control “someShortname” is maybe shooting  app performance in the foot
>
>
> ??
>
>
> BR
>
>
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode



More information about the use-livecode mailing list