Skip to content

Perf: Enable Lark grammar cache and introduce snippet parse cache #127

Description

@webmaven

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

  1. Lark Grammar Cache: Utilize Lark's built-in grammar cache argument (Lark(..., cache=...)) so grammar compilation doesn't repeat across worker processes or initializations.
  2. 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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions