Problem
In test-driven workflows and multi-view generation pipelines (such as Golem's render="source,asg,html,preview"), parse_to_ast() is invoked repeatedly on small AsciiDoc snippets.
Because Lark operates in pure Python with parser="earley" and ambiguity="resolve", repeated chart expansion and grammar initialization impose high cumulative CPU costs, which are amplified under Python test coverage tracing.
Proposed Solutions
- Lark Grammar Cache: Utilize Lark's built-in grammar cache argument (
Lark(..., cache=...)) so grammar compilation doesn't repeat across worker processes or initializations.
- Snippet Cache: For small snippets (e.g.
< 4096 characters) or identical docstrings, provide an optional LRU cache for parse_to_ast() AST results (or a frozen ASG representation).
Problem
In test-driven workflows and multi-view generation pipelines (such as Golem's
render="source,asg,html,preview"),parse_to_ast()is invoked repeatedly on small AsciiDoc snippets.Because Lark operates in pure Python with
parser="earley"andambiguity="resolve", repeated chart expansion and grammar initialization impose high cumulative CPU costs, which are amplified under Python test coverage tracing.Proposed Solutions
Lark(..., cache=...)) so grammar compilation doesn't repeat across worker processes or initializations.< 4096characters) or identical docstrings, provide an optional LRU cache forparse_to_ast()AST results (or a frozen ASG representation).