Phenomenal optimization technique!
i discovered amazing way of optimizing script, thought
i'd share.
i have script adds line numbers indesign document
(www.freelancebookdesign.com under scripting tab).
it works adding text frame alongside each indesign frame , adds
numbers in frame.
i've done quite lot of optimization on already, , script
starts @ nice pace, slows down.
so on book 100 pages, it's pretty quick. adding line numbers
to 500-page book becomes slow, because last 1/3 or of
pages script has slowed crawl.
now, many of recognize symptoms: each page,
new text frame + contents has been created, after 200 or
operations, undo queue has become long.
the question becomes: how flush undo queue.
now, remember reading once suggestion "save as". thing is,
don't want "save as" user's document -- won't thank me if
they need undo few steps before ran script!
of course, script uses doscript call
undomodes.entire_script it's single step. , know
fast_entire_script isn't safe use -- it's quite buggy.
what figured out, , quite proud of , break loop
that goes through 500 pages 10 loops of around 50 pages each
-- , run each loop separate doscript (entire_script) call.
we have nested doscript.
the thing undomodes.entire_script seems undo queue
is still written to, , when doscript call ends,
deleted , turned 1 step. each time doscript call finishes,
even if call involved thousand steps, reduced
a single undo step when finishes -- , equivalent of
"save as".
and since seems take exponentially longer execute command
longer undo queue is, dividing queue 10 chunks of 50
(instead of single chunk of 500), huge amount of time saved.
every 50 iterations, undo queue flushed, , script therefore
continues @ same pace when first run. (obviously, if
there thousands of iterations, idea add
another nested doscript call).
so, case in point: experiments 500-page book have show 360%
increase in efficiency! used take 288 seconds takes 80 seconds!
i'm pretty impressed!
do have better way of dealing undo slowness?
ariel
nice one, ariel. sharing.
peter
More discussions in InDesign Scripting
adobe
Comments
Post a Comment