Page 1 of 1

(custom) properties are unwieldy?

Posted: Thu Sep 24, 2015 8:07 am
by rinzwind
Look at this...

set the p1 of btn id tid to the p1 of btn id tid + 1

It's lengthy to write. frustratingly so if you need to refer to multiple properties multiple times in compare and assign statements.. and inefficient too...

while
add 1 to the p1 of btn id tid
is not valid code.

and this:
put the customProperties of btn id tid into p
add 1 to p["p1"]
set the customProperties of btn id tid to p

The above is a bit faster than the first example... while it looks like it should be slower. That says something about the efficiency of custom property lookups.

LiveCode won't won't optimize lots of serial object lookups either (if you use the name instead of the id it becomes much slower with lots of objects).

Maybe add something like this for efficiency..
put ref btn tname into trefbtn
add 1 to trefbtn["p1"]
or
add 1 to treftbn.p1

Some code to play around with (results here: a:662 b:30 c:24 d:6 e:2):

Code: Select all

command Test
   local tname, tid, t1, v, p
   if there is not a group "TestGroup" then
      lock screen
      create group "TestGroup"
      repeat with i = 1 to 1000
         put i & "b" into tname
         create btn tname in group "TestGroup"
         put the id of the last button of me into tid
         set the p1 of btn id tid to i
         set the p2 of btn id tid to i * i
      end repeat
      unlock screen
   end if
   put "555b" into tname
   put the id of btn tname into tid
   put the millisecs into t1
   repeat with i = 1 to 10000
      set the p1 of btn tname to the p1 of btn tname + 1
   end repeat
   put "a:" & the millisecs - t1 & space after field "Results"
   
   put the millisecs into t1
   repeat with i = 1 to 10000
      set the p1 of btn id tid to the p1 of btn id tid + 1
   end repeat
   put "b:" & the millisecs - t1 & space after field "Results"
   
   put the millisecs into t1
   repeat with i = 1 to 10000
      put the customProperties of btn id tid into p
      add 1 to p["p1"]
      set the customProperties of btn id tid to p
   end repeat
   put "c:" & the millisecs - t1 & space after field "Results"
   
   put the millisecs into t1
   put the customProperties of btn id tid into p
   repeat with i = 1 to 10000
      add 1 to p["p1"]
   end repeat
   set the customProperties of btn id tid to p
   put "d:" & the millisecs - t1 & space after field "Results"
   
   put the millisecs into t1
   put the p1 of btn id tid into v
   repeat with i = 1 to 10000
      add 1 to v
   end repeat
   set the p1 of btn id tid to v
   put "e:" & the millisecs - t1 & space after field "Results"
end Test

Re: (custom) properties are unwieldy?

Posted: Thu Sep 24, 2015 8:19 am
by rinzwind
I think it would be relatively easy to implement a object and property lookup cache (or is there already?). At least that would fix some inefficient programming and at best speed up operation of LiveCode everywhere.