Hi there: I'm parsing a large html file and replacing placeholders marked as text strings with different text content, and the way I'm doing it seems to be taking a very long time. It takes 2 seconds on my MacPro, but 19 seconds on my Linux container. Can you think of a more efficient way of doing this?
replace "##PNPL" WITH field "TWSprof" in dashboardhtml
replace "##PL" WITH field "accountPL" in dashboardhtml
replace "##CCTNAME" WITH field "anonName" in dashboardhtml
replace "##CLSDTRDS" WITH closedpos in dashboardhtml
... etc...
It's a very convenient way of customizing an html template page, but I think the replace string search is the part that is very inefficient.
on mouseUp
put the ticks into temp
put "xyz" into var
repeat 1000000
replace "xyz" with "aaa" in var -- twice as fast
replace "xyz" with field 1 in var
end repeat
answer the ticks - temp
end mouseUp
Thanks. I think the most important bit of data that should be in a var is the main html file that contains all of the replacement placeholders (from my code below, "dashboardhtml"), which is quite large, and that is already in a variable. I could try to put all of the small bits of data into variables first, but I just don't see that being any faster (you have to place them into the var first anyhow and that means moving the data from the field into the variable.
put VERYlargeHTMLfile into dashboardhtml
replace "##PNPL" WITH field "TWSprof" & return in dashboardhtml
replace "##PL" WITH field "accountPL" in dashboardhtml
replace "##CCTNAME" WITH field "anonName" in dashboardhtml
replace "##CLSDTRDS" WITH closedpos in dashboardhtml
replace "##CCUNTVLU" WITH field "myvalue" in dashboardhtml
replace "##CCUNTTYP" WITH Atype in dashboardhtml
replace "##MS" WITH the label of button "multisysmenu" in dashboardhtml
replace "##SYMBLS" WITH loadedsymbs in dashboardhtml
replace "##FLTRS" WITH "no filters" in dashboardhtml
replace "##PS" WITH positions in dashboardhtml
replace "##CPTL" WITH field "capital" in dashboardhtml
replace "##RSK" WITH field "riskperbar" in dashboardhtml
replace "##indexembed" WITH theINDEX in dashboardhtml
I'd be curious to know what you find out. Using replace, the engine has to parse the long html file 12 times. Using merge, I think it does it all in one pass.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
Probably I need to confirm this, but as far as I know
everytime that you access data inside a field, then
Livecode engine sends messages... but this could have
changed in recent Livecode versions.
Richard Gaskin have an utility that could confirm this:
4w Props or 4w umbrella.
dunno if it helps here, but a while ago I did some timings & optimizations with replace loops. Got some very nice speed improvements for large files. To be found here.
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!