Skip to content

perf(prediction): add an opt-in full-context DFA with caller-context edges #335

Description

@tinovyatkin

Source

Tunnel Vision's optimized fork can cache full-context (LL) prediction in the
decision DFA, not only local-context (SLL) prediction:

The fork maintains a separate full-context start state and incrementally follows
caller return states through context edges before taking the next token edge.
It is disabled by default because retained states, configurations, and contexts
can grow substantially.

Applicability

Applicable. The Rust runtime already performs full-context prediction and
owns compact learned-DFA/context storage, but its
ParserDfa
contains only SLL token edges plus local/precedence start states. The
adaptive_predict_full_context
path rebuilds and simulates LL configurations rather than learning
caller-context edges.

#207 added a narrower bounded replay memo for predicate-free full-context
resolutions. A full-context DFA is complementary: it can retain intermediate LL
states and context transitions, and it should be evaluated as an opt-in
alternative rather than silently duplicating both caches.

This is source-level applicability research only; no speedup is claimed without
future measurement.

Proposed work

  • Add an opt-in, default-off full-context DFA mode.
  • Represent full-context start states and caller-context edges with compact IDs
    in the existing hot/cold DFA architecture; do not introduce per-state object
    maps.
  • Consume interned caller return states incrementally, matching the fork's
    context-symbol/context-edge model.
  • Define bounded retention and expose state/context-edge memory statistics.
  • Specify interaction with perf(prediction): memoize full-context LL resolutions by interned context — repeated SLL-conflict retries dominate ambiguous-grammar parses #207's replay memo: select, compose with a proven
    bound, or replace it, but do not retain two unaccounted caches for the same
    work.
  • Preserve precedence DFA, predicates, exact ambiguity diagnostics, shared-store
    import/remapping, and clear_dfa() behavior.

Acceptance criteria

  • The option is disabled by default and has a documented memory tradeoff.
  • Repeated identical LL predictions can hit learned full-context states
    without re-running the complete LL closure.
  • Caller contexts that share a prefix reuse context edges; distinct contexts
    cannot alias.
  • Cache clearing and shared prediction-store import preserve ContextId
    ownership invariants.
  • ANTLR runtime conformance remains green with zero skipped cases.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions