Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
Simon Knight
- Posts: 854
- Joined: Wed Nov 04, 2009 11:41 am
- Location: Gunthorpe, North Lincs, UK
Post
by Simon Knight » Fri Sep 24, 2021 7:42 am
Hi,
I have a stack that has five cards and each card holds sixty groups each comprises two buttons and a field. I have a helper routine that deletes all these groups and replaces them with copies of a master group held on a sixth card. I call the helper routine from the message box and the update routine runs without error. However, Livecode takes a very long time to hand back control to the IDE and my computer's fans start running during this time. Apple's activity monitor show that Livecode is using 90% cpu during this period.
My guess is that Livecode is taking time to process the deletion and addition of three hundred groups which are some twelve hundred items. Any thoughts ? My handler is below.
Simon
Code: Select all
On IDEUpdateControlsOnTagCards
# Called from the message box when adding new cards
# Used to update the card with an updated control where
# the updated control is DZ-1 held on the ref card
# Used when designing the application not when running
lock screen
Repeat with tcardNo = 1 to 5
put "TagList" & tcardNo into tCardName
put 0 into tCounter
put the the number of groups in card tCardName of me into tTotalGroupCount
repeat with i = tTotalGroupCount down to 1
Delete group i of card tCardName of me
end repeat
put 0 onto tRowNo
put 0 into tColumn
repeat with n = 1 to 60
if n = 1 then
put 1 into tColumn
put 30 onto tLeft
put 0 into tRowNo
else
Switch n
Case 16
add 300 to tLeft
put 0 into tRowNo
break
Case 31
add 300 to tLeft
put 0 into tRowNo
break
Case 46
add 300 to tLeft
put 0 into tRowNo
break
Case 61
add 300 to tLeft
put 0 into tRowNo
break
end Switch
end if
add 1 to tRowNo
put 5 + (tRowNo*46) into tTop -- tRow is the remainder
copy group "DZ-1" of card RefData of me to card tCardName of me
set the name of it to "DZ-" & n
set the left of it to tLeft
set the top of it to tTop
end repeat
Put "1star" into field "tags" of group "DZ-1" of card tCardName of me
Put "2star" into field "tags" of group "DZ-2" of card tCardName of me
Put "3star" into field "tags" of group "DZ-3" of card tCardName of me
Put "4star" into field "tags" of group "DZ-4" of card tCardName of me
Put "5star" into field "tags" of group "DZ-5" of card tCardName of me
Put "Selected" into field "tags" of group "DZ-6" of card tCardName of me
Put "Rejected" into field "tags" of group "DZ-7" of card tCardName of me
Put "Portrait" into field "tags" of group "DZ-8" of card tCardName of me
Put "Model" into field "tags" of group "DZ-9" of card tCardName of me
Put "Landscape" into field "tags" of group "DZ-10" of card tCardName of me
Put "Street" into field "tags" of group "DZ-11" of card tCardName of me
Put "Natural-History" into field "tags" of group "DZ-12" of card tCardName of me
Put "Macro" into field "tags" of group "DZ-13" of card tCardName of me
Put "Print" into field "tags" of group "DZ-14" of card tCardName of me
wait 1 seconds with messages
end Repeat
unlock screen
answer "Complete, all " & tcardNo && "cards have been updated with master control."
end IDEUpdateControlsOnTagCards
best wishes
Skids
-
SparkOut
- Posts: 2852
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Fri Sep 24, 2021 8:09 am
First question is whether you have the Project Browser open at the time?
I believe the PB refreshes in its entirety for each and every single edit made, so it will redraw over and over again as it maps all 1200 objects to the tree.
If the Project Browser is already closed, then that's another issue.
-
bn
- VIP Livecode Opensource Backer
- Posts: 4003
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Post
by bn » Fri Sep 24, 2021 8:44 am
Hi Simon,
could you try to wrap the code in "lock messages"/"unlock messages"?
Kind regards
Bernd
-
Simon Knight
- Posts: 854
- Joined: Wed Nov 04, 2009 11:41 am
- Location: Gunthorpe, North Lincs, UK
Post
by Simon Knight » Fri Sep 24, 2021 10:13 am
Yes I had the project browser open and it seems to be the cause of the delay in handing back control to the IDE. I'll add some lines to close the browser before the main body of the code runs.
Thanks
Simon
best wishes
Skids
-
bn
- VIP Livecode Opensource Backer
- Posts: 4003
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Post
by bn » Fri Sep 24, 2021 10:33 am
Simon Knight wrote: ↑Fri Sep 24, 2021 10:13 am
Yes I had the project browser open and it seems to be the cause of the delay in handing back control to the IDE. I'll add some lines to close the browser before the main body of the code runs.
I would be interested in the results of additionally to closing the Project Browser addding lock messages/unlock messages
Kind regards
Bernd
-
Simon Knight
- Posts: 854
- Joined: Wed Nov 04, 2009 11:41 am
- Location: Gunthorpe, North Lincs, UK
Post
by Simon Knight » Fri Sep 24, 2021 11:30 am
Hi Bernd,
It is tricky to measure as it is not clear exactly when full control is handed back to the IDE as the IDE allows edits but the "Apply" button fails to go active. I tried lock messages with the browser open and closed and the significant difference was with the project browser closed. However I will have another look.
Simon
best wishes
Skids
-
stam
- Posts: 2686
- Joined: Sun Jun 04, 2006 9:39 pm
- Location: London, UK
Post
by stam » Fri Sep 24, 2021 11:52 am
Looks like heavy duty nested loops...
I can see you've added 'wait 1 seconds with messages' at the end of the outer loop.
Does it make a difference if you add this (or even 'wait 0 milliseconds with messages') to the start of the inner loop? (or both loops?)
S.
-
Simon Knight
- Posts: 854
- Joined: Wed Nov 04, 2009 11:41 am
- Location: Gunthorpe, North Lincs, UK
Post
by Simon Knight » Fri Sep 24, 2021 11:58 am
OK Lesson 1, always listen to Bernd!
I added some start end timers and also used my computers clock and ran the handler several times. The timers reported to the message box with a put statement. Here are the results :
Project Browser CLOSED.
Run (1) with messages: 8.911 seconds.
Run (2) without messages 5.126 seconds.
In all runs the reported times "felt" correct against the computer clock and the IDE was back in full control.
Project Browser OPEN.
Run (3) with messages 9.664 seconds reported but the it took at least 78 seconds to post the incorrect time in the message box. This was repeatable.
Run (4) without messages 5.123 seconds - again "felt" correct when compared with computers clock.
I've seen similar when I've played with datagrids, its as if the massage path gets lost in the woods and is very hard to debug.
Simon
best wishes
Skids
-
bn
- VIP Livecode Opensource Backer
- Posts: 4003
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Post
by bn » Fri Sep 24, 2021 12:15 pm
Thank you for testing.
I did not look very close at the code but Sparkout has a very good point regarding wait 1 seconds with messages.
Kind regards
Bernd
-
Simon Knight
- Posts: 854
- Joined: Wed Nov 04, 2009 11:41 am
- Location: Gunthorpe, North Lincs, UK
Post
by Simon Knight » Fri Sep 24, 2021 12:46 pm
Yes I forgot I had added the wait, here are some more results:
Project Browser Open:
Wait 0 ms with messages - True
With Lock Messages - False
Handler claims 5.028 seconds, actual run time 80 seconds
Wait 0 ms with messages - False, line commented out.
With Lock Messages - False
Handler claims 4.581 seconds, actual run time 80 seconds
Wait 0 ms with messages - False, line commented out.
With Lock Messages - True
Handler reports 0.092 seconds to quick to measure on stopwatch
S
best wishes
Skids
-
bn
- VIP Livecode Opensource Backer
- Posts: 4003
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Post
by bn » Fri Sep 24, 2021 8:20 pm
Simon Knight wrote: ↑Fri Sep 24, 2021 12:46 pm
Project Browser Open:
...
...
Wait 0 ms with messages - False, line commented out.
With Lock Messages - True
Handler reports 0.092 seconds to quick to measure on stopwatch
Thanks for posting the test results.
That sounds like a nice speed increase.
Kind regards
Bernd