Skip to main content

Module incremental_v2

Module incremental_v2 

Source
Expand description

Second-generation incremental parsing with improved node reuse. Incremental parsing implementation and helpers. Incremental parsing implementation with comprehensive tree reuse

This module provides a high-performance incremental parser that achieves significant performance improvements over full parsing through intelligent AST node reuse. Designed for integration with LSP servers and real-time editing scenarios.

§Performance Characteristics

  • Sub-millisecond updates for simple value edits (target: <1ms)
  • Node reuse efficiency of 70-90% for typical editing scenarios
  • Graceful fallback to full parsing for complex structural changes
  • Memory efficient with LRU cache eviction and Arc<Node> sharing
  • Time complexity: O(n) for reparsed spans with bounded lookahead
  • Space complexity: O(n) for cached nodes and reuse maps
  • Large file scaling: Tuned to scale for large file edits (50GB PST-style workspaces)

§Supported Edit Types

  • Simple value edits: Number and string literal changes
  • Variable name edits: Identifier modifications within bounds
  • Whitespace and comment edits: Non-structural changes
  • Multiple edits: Batch processing with cumulative position tracking

§Usage Example

use perl_parser::incremental_v2::IncrementalParserV2;
use perl_parser::edit::Edit;
use perl_parser::position::Position;

let mut parser = IncrementalParserV2::new();

// Initial parse
let source1 = "my $x = 42;";
let tree1 = parser.parse(source1)?;

// Apply incremental edit
let edit = Edit::new(
    8, 10, 12, // positions: "42" -> "9999"
    Position::new(8, 1, 9),
    Position::new(10, 1, 11),
    Position::new(12, 1, 13),
);
parser.edit(edit);

// Incremental reparse (typically <1ms)
let source2 = "my $x = 9999;";
let tree2 = parser.parse(source2)?;

// Check performance metrics
println!("Nodes reused: {}", parser.reused_nodes);
println!("Nodes reparsed: {}", parser.reparsed_nodes);

Structs§

IncrementalMetrics
Comprehensive performance metrics for incremental parsing analysis
IncrementalParserV2
High-performance incremental parser with intelligent AST node reuse
IncrementalTree
A parse tree with incremental parsing support and node mapping