Recently, Vitalije and I have collaborated to produce code that reads all
files in LeoPyRef.leo in about 4.5 sec. (on my machine).
The heart of that code is:
def load_derived_file(lines):
'''A generator yielding tuples: (gnx, h, b, level).'''
flines = tuple(enumerate(lines))
<< scan header, setting first_lines & delims >>
<< define get_patterns >>
patterns = get_patterns(delim_st, delim_en)
<< handle the top node >>
<< iterate all other lines >>
<< yield all nodes >>
<< iterate all other lines >> is heart of the code:
# Append lines to body, changing nodes as necessary.
<< init the grand iteration >>
for i, line in flines[start:]:
# These three sections must be first.
<< handle verbatim lines >>
<< unindent the line if necessary >>
<< short-circuit later tests >>
# The order of these sections does matter.
<< handle @all >>
<< handle @others >>
<< handle start of @doc parts >>
<< handle start of @code parts >>
<< handle section refs >>
<< handle node_start >>
<< handle @-leo >>
<< handle directives >>
<< handle in_doc >> # Apparently, must be last.
# A normal line.
body.append(line)
# Handle @last lines.
if i + 1 < len(flines):
nodes.body[topgnx].extend('@last %s'%x for x in flines[i+1:])
All the ideas here are Vitalije's except << short-circuit later tests >>
which decreases the time taken from 6.0 sec to 4.5 sec, a performance
increase <https://www.skillsyouneed.com/num/percent-change.html> of
((6.0-4.5)/6.0)*100 = 25%.
*Summary*
There will be a lot of new work adapting the code above to at.scanText4 and
its helpers.
The goal will be to read all of Leo's external files in under 5 seconds.
This is worth almost any amount of work. It would obsolete the need for
caching.
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.