Skip to content

Avoid rebuilding full semantic analysis state for repeated ToolService queries #356

Description

@Teakowa

Goal

Make repeated semantic queries over one loaded Wright session reuse the semantic state that is valid for that program/configuration instead of reconstructing full-program analysis state for each query.

Context

ToolService holds one loaded canonical program, but its semantic-query path constructs a fresh SemanticService for individual query operations. The canonical service construction builds semantic indexes and analysis-derived data over the loaded program. Query-heavy consumers such as inspect/tool/agent workflows can therefore repeat work that is invariant within the same loaded session.

This is a performance and allocation issue, not an API redesign objective. The change must preserve query semantics and should be justified by measurements on representative Wright workloads rather than assumed percentage improvements.

Scope

  • Measure the current cost of repeated Rules, Symbols, References, Usage, Cfg, findings, persistent-object, and lint-related queries over representative canonical Workshop inputs.
  • Identify which semantic/index/analysis products are invariant for the lifetime of one loaded ToolService and which depend on lint configuration or request-specific inputs.
  • Reuse invariant semantic state across requests without weakening configuration correctness or introducing stale results.
  • Review inspect construction for avoidable in-process JSON Value round-trips and repeated per-symbol service requests; use a structured internal path where this materially removes measured overhead without expanding the public contract.
  • Preserve the existing transport-neutral ToolService request/response surface.

Non-goals

  • Changing lint/analyze semantics or rule ownership.
  • Adding a general cache framework or cross-session/global cache.
  • Exposing internal SemanticIndex representation as a public API solely for optimization.
  • Optimizing unmeasured micro-costs unrelated to repeated semantic-query work.
  • Changing provider/source-language semantics.

Acceptance criteria

  • Representative measurements demonstrate the repeated semantic work present before the change and record the workload used for comparison.
  • Repeated semantic queries over one unchanged loaded program do not rebuild invariant full-program semantic/index state for each request.
  • Lint configuration-dependent results remain correct when the effective configuration differs from the default query path.
  • inspect avoids repeated serialization/deserialization or per-symbol query loops where the same result can be obtained from already-built internal semantic state, when supported by the measured workload.
  • Public ToolRequest/ToolResponse behavior and deterministic output remain unchanged unless a separately documented contract defect is discovered.
  • Memory ownership/lifetimes remain local to the loaded service/session; no global mutable cache is introduced.
  • Relevant service, inspect, CLI, and embedding tests remain green.
  • Independent ablation of the reuse path restores the measured repeated-work regression.

Dependencies / ownership

  • wright: owns ToolService, inspect composition, analyzer/query orchestration, and performance of its product/tooling surfaces.
  • workshop-rs: remains the owner of canonical Workshop semantics; this issue must not duplicate or cache source-owner semantics outside the existing canonical program contract.

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

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions