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

- parser.py: added a comment on motivation for new memoization algorithm

parent b75d6237
...@@ -235,6 +235,11 @@ def add_parser_guard(parser_func): ...@@ -235,6 +235,11 @@ def add_parser_guard(parser_func):
rlen = location - (0 if node is None else node.len) rlen = location - (0 if node is None else node.len)
rest = grammar.document__[-rlen:] if rlen else '' rest = grammar.document__[-rlen:] if rlen else ''
return node, rest 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!?
try: try:
location = len(text) # mind that location is always the distance to the end location = len(text) # mind that location is always the distance to the end
......
...@@ -83,7 +83,7 @@ def mem_profile(func): ...@@ -83,7 +83,7 @@ def mem_profile(func):
snapshot = tracemalloc.take_snapshot() snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics('lineno') top_stats = snapshot.statistics('lineno')
print("[ Top 20 ]") print("[ Top 20 ]")
for stat in top_stats[:20]: for stat in top_stats[:40]:
print(stat) print(stat)
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
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