Slowness of LC 7.0 (dp5) Text Functions

Discussion about LiveCode Global Jam events and activities

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Locked
nower
Posts: 47
Joined: Wed May 22, 2013 11:02 pm

Slowness of LC 7.0 (dp5) Text Functions

Post by nower » Tue May 27, 2014 2:44 am

I have a language change functionality in a stack of mine that allows the user to switch between two languages.
As part of the switch, about 370 text items (with a total of less than 150 kilobytes) are replaced with text from the other language.

If I run the stack on pre 7.0 versions of LC, the function takes less than a second.
On LC 7.0 (dp5) the process takes about 50 seconds (sometimes a few seconds more, sometimes a few seconds less)!!
This in on Windows 7 Prof, on an i7-2720 QM processor with plenty of RAM.

Here is the code of the function.

Code: Select all

#-----------------------------------------------------------------
# Input: Language supported by this app
# Output: Language
#-----------------------------------------------------------------
function changeLanguage thisLanguage
   
   set itemDelimiter to "|"
   local tCardName
   local tLCategories, tUCategories
   local tLQuotes, tUQuotes
   local tID
   local tLine
   local tText
   local tStartTime, tEndTime
   
   put the milliseconds into tStartTime
   
   put "Language" & thisLanguage into tCardName
   
   if thisLanguage <> "English" then
      put field "itemList" of card tCardName of stack "EQLanguages" into gLocalizedItems
   else
      put empty into gLocalizedItems
   end if
   
   put field "CategoriesList" of card tCardName of stack "EQLanguages" into tLCategories
   put field "QuotesList" of card tCardName of stack "EQLanguages" into tLQuotes
   put field "CategoriesList" of card "QuotesSettings" of stack "EQUserdata" into tUCategories
   put field "QuotesList" of card "QuotesSettings" of stack "EQUserdata" into tUQuotes
   
   # simply transfer items for categories as there are no user-defined items
   # alltogether 10 lines of text
   put 0 into tLine
   repeat for each line thisLine in tLCategories
      add 1 to tLine
      put item 2 of thisLine into item 2 of line tLine of tUCategories
   end repeat
   
   # make sure to only transfer application-defined items and leave user-defined items alone
   # alltogether 360 lines of quotes
   repeat for each line thisLine in tLQuotes
      put item 1 of thisLine into tID
      put lineOffset(tID, tUQuotes) into tLine
      put item 2 of thisLine into item 2 of line tLine of tUQuotes
   end repeat
   
   put tUCategories into field "CategoriesList" of card "QuotesSettings" of stack "EQUserdata"
   put tUQuotes into field "QuotesList" of card "QuotesSettings" of stack "EQUserdata"
   
   put thisLanguage into gLanguage
   set the EQLanguage of stack "EQUserdata" to thisLanguage

   put the milliseconds into tEndTime
   answer "The function took " & (tEndTime - tStartTime) & " milliseconds"
   
   return thisLanguage
   
end changeLanguage
Let me know if you need further info to research.

The massive slowness of this functionality on LC 7.0 is really scary - it would be prohibitive for using it live.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Slowness of LC 7.0 (dp5) Text Functions

Post by Simon » Tue May 27, 2014 3:26 am

Hi nower,
Try moving your tStartTime and tEndTime to see if you can define where the time is taken.
"repeat for each line thisLine in tLQuotes"?
"put tUQuotes into field..."?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 474
Joined: Thu Sep 04, 2008 6:23 am
Location: Melbourne Australia

Re: Slowness of LC 7.0 (dp5) Text Functions

Post by jameshale » Tue May 27, 2014 3:49 am

Yes there is a massive slowness in text style functions, well specifically in setting the htmltext and modifying text styles.
The slowdown first appeared in LC 6.x compared to LC5.5 but with the release of LC 7 has taken on a whole new scale.
There is a bug report http://quality.runrev.com/show_bug.cgi?id=11817 wihich has the result of some testing (with test stack).

In looking at the LC DP5 release I noticed the slowdown first hit with just setting the HTMLtext of a field.

The hit is partially dependant on the size of the line (paragraph). Something not there in LC 6.
e.g. setting the htmltext of a field to a 1000 line text sample.
LC7DP5: 100 secs
LC6.6.1: 2.7 secs
putting a <p> before each line (thus making 1000 lines now 1000 paragraphs html wise)
LC7DP5: 6 secs
LC6.6.1: 2.5 secs
Still a performance hit over 6.6.1 but nowhere near as great.

Here is a test stack that produced the results quoted.
Attachments
HTMLstyle test.livecode.zip
timing test for htmltext
(3.14 KiB) Downloaded 406 times

nower
Posts: 47
Joined: Wed May 22, 2013 11:02 pm

Re: Slowness of LC 7.0 (dp5) Text Functions

Post by nower » Tue May 27, 2014 4:16 am

I followed your advice, Simon, and timed the different statements.

Pretty much all of the slowness is in this loop:

Code: Select all

   repeat for each line thisLine in tLQuotes
      put item 1 of thisLine into tID
      put lineOffset(tID, tUQuotes) into tLine
      put item 2 of thisLine into item 2 of line tLine of tUQuotes
   end repeat
Statement 2 in the loop gets increasingly slower, from 1 ms in the beginning to almost 250 ms towards the end.
Statement 3 in the loop also gets slower, but much less, from 1 ms in the beginning to about 20 ms towards the end.
In a was this makes sense as LC has to read through more text as the function progresses (it replaces text in 360 lines, starting at the beginning and moving towards the end.
But I am still surprised that it takes that long to find text in a field of such moderate size.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Slowness of LC 7.0 (dp5) Text Functions

Post by Simon » Tue May 27, 2014 5:10 am

"put item 2 of thisLine into item 2 of line tLine of tUQuotes"
I wonder if you should be doing that?
Maybe
"put tUQuotes into tTempQuotes"
do your repeat
"put item 2 of thisLine into item 2 of line tLine of tTempQuotes"
after the repeat
put tTempQuotes into tUQuotes

My thinking is you are changing a variable that you are using to make the repeat from.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

nower
Posts: 47
Joined: Wed May 22, 2013 11:02 pm

Re: Slowness of LC 7.0 (dp5) Text Functions

Post by nower » Tue May 27, 2014 2:14 pm

Hi Simon,

thanks for your suggestion.

The code works as it is.
The repeat works on tLQuotes, and I update tUQuotes, no problem there.

The problem is just that the code is 50 - 100 times slower on LC 7.0 than on previous versions.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Slowness of LC 7.0 (dp5) Text Functions

Post by Simon » Tue May 27, 2014 7:26 pm

Hi nower,
Sure it works, but that wasn't the point of my suggestion.
It's up to you to see if you can find a solution to the speed issue. What else have you tried?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

nower
Posts: 47
Joined: Wed May 22, 2013 11:02 pm

Re: Slowness of LC 7.0 (dp5) Text Functions

Post by nower » Tue May 27, 2014 11:54 pm

Hi Simon,

for me the point is not to find a workaround in my app for the speed issue.

I think it is something for the LC team to look at.
If pretty general text functions take 50 - 100 times longer on LC 7 than on previous versions, the LC implementation should be reviewed.

I would think the goal is that stacks which worked fine on previous versions of LC should be able to run on LC 7 without modifications, especially if they use just pretty general functionality and nothing overly fancy.

In any case, thanks for your attempt to help.
Werner

Locked

Return to “LiveCode Global Jam”