Commit b930b98d authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

- added a comment on motivation for new memoization algorithm

parent b75d6237
......@@ -235,6 +235,11 @@ def add_parser_guard(parser_func):
rlen = location - (0 if node is None else node.len)
rest = grammar.document__[-rlen:] if rlen else ''
return node, rest
# NOTE: An older and simpler implementation of memoization
# relied on `parser.visited[location] == node, rest`. Although,
# rest is really just a substring of one and the same document,
# this resulted in an explosion of memory usage. Seems as if
# `rext = text[i:]` really copies the sub-string!?
location = len(text) # mind that location is always the distance to the end
......@@ -83,7 +83,7 @@ def mem_profile(func):
snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics('lineno')
print("[ Top 20 ]")
for stat in top_stats[:20]:
for stat in top_stats[:40]:
if __name__ == "__main__":
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment