Slowdown when putting symbols into image data
Alex Tweedly
alex at tweedly.net
Tue Sep 9 19:17:16 EDT 2014
On 09/09/2014 20:09, J. Landman Gay wrote:
> On 9/9/2014, 12:51 PM, William Prothero wrote:
>> Seems I’ve found the offending line in my draw script. Its:
>>
>>> > put byte 1 to tLength of tbrushBinaryData into byte tNewStart * 4
>>> - 3 to tNewStart*4 - 3 + tLength -1 of imgdata -- insert
>>> brushimageData into image
>> If I comment out this line, the symbols are drawn in 2.85 seconds,
>> more than a factor of 10 speedup.
>
> This would be similar to using a "repeat with x = 1 to 1000"
> structure. Every time through the loop the engine has to count from
> byte 1 to tNewStart. An image has lots of bytes, so all that counting
> makes it slow.
No, it wouldn't be similar to that, or at least two reasons:
1. accessing bytes (or historically chars) is 'direct' - the enginge can
calculate where byte N is and just accesses it directly - in contrast to
needing to traverse thrugh counting which it does need to do for item,
line, word, .... char wa historically the exception, and very quick
because of that. With the move to Unicode, char becomes less 'direct',
but byte will remain direct, and hence should be the quickest one to use.
2. there is a repeat loop over the number of rows in the brushdata - but
there is no repeat loop within this statement (except inside the
engine). It's a single 'put' command, which should copy a large block of
bytes into another (hopefully same sized) block of byte positions.
Notwithstanding that, all the rest of your message, and the advice
given, is correct and good - but I don't see any reason why this
statement should be any slower in 7.0 than in 6.x. I'll go experiment ....
-- Alex.
More information about the use-livecode
mailing list