Skip to content

perf: lazy libcst load and SyntaxVerifier hot-path tweaks #142

@omsherikar

Description

@omsherikar

Summary

SyntaxVerifier.verify does import libcst inside the method on every invocation. That adds import overhead per fix/verify cycle even when short-circuiting could be optimized. Also, dangerous-call and import-count logic walks ASTs that could share a single ast.parse if the engine provides it (see related issue on shared AST).

Suggested direction

  • Move libcst to module-level lazy import pattern (e.g. import on first use cached in a module global) or top-level import if dependency is always present for verification.
  • After shared-parse work lands, reuse one ast for _find_dangerous_calls / _count_imports where it reduces walks.

Acceptance

  • Reduced per-call import cost in profiles or micro-benchmarks.
  • Behavior unchanged for CST round-trip failures and dangerous-call detection.

Code

  • refactron/verification/checks/syntax.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions