View Source cure_lsp_performance (cure v0.7.0)

LSP Performance Optimization

This module provides performance optimizations for real-time LSP verification:

Optimizations

1. Query Batching

  • Batch multiple constraints into a single SMT query
  • Use multiple (assert ...) before (check-sat)
  • Reduces SMT solver startup overhead

2. Timeout Tuning

  • Short timeout (500ms) for LSP interactive use
  • Long timeout (5000ms) for full compilation
  • Configurable per-context timeouts

3. Background Verification

  • Queue verification tasks
  • Process in background worker gen_server
  • Return cached results immediately
  • Cancel verification on file close

4. Hot Path Optimization

  • Fast constraint extraction (<50ms)
  • Optimized SMT-LIB generation
  • AST caching to avoid re-parsing

Performance Targets

  • Constraint extraction: <50ms
  • SMT query (simple): <100ms
  • SMT query (complex): <500ms
  • Full document verification: <1s
  • Cache hit rate: >80%

Architecture

LSP Request
    
Fast Path: Cache Hit  Return immediately (<10ms)
    
Slow Path: Cache Miss
    
Background Worker: Queue task
    
Batch Constraints  Single SMT Query
    
Return result + Update cache

Summary

Functions

cancel_verification(Uri)

-spec cancel_verification(binary()) -> ok.

clear_queue()

-spec clear_queue() -> ok.

code_change(OldVsn, State, Extra)

get_stats()

-spec get_stats() -> map().

handle_call/3

handle_cast/2

handle_info/2

init(Opts)

set_timeout(Context, TimeoutMs)

-spec set_timeout(atom(), integer()) -> ok.

start_link()

-spec start_link() -> {ok, pid()} | {error, term()}.

start_link(Opts)

-spec start_link(map()) -> {ok, pid()} | {error, term()}.

stop()

-spec stop() -> ok.

terminate(Reason, State)

verify_async(Uri, AST, Context)

-spec verify_async(binary(), term(), atom()) -> {ok, reference()}.

verify_batch(Items, Context)

-spec verify_batch([{binary(), term()}], atom()) -> {ok, [map()]}.