This directory contains the design analysis and benchmark results for the hierarchical lexical scope filtering feature.
Feature: Contextual code completion with hierarchical lexical scopes Timeline: October 2025 Final Result: Official production feature with 4.7% improvement over baseline Status: Complete - 233 tests passing
Hierarchical scope completion enables contextual code completion that respects lexical scoping rules. When a user types a partial identifier, the completion system only suggests identifiers visible from the current scope.
Design Document - Comprehensive Approach Analysis
Key Findings:
Benchmark Results - Production Validation
Performance Results:
| Approach | Average Time | vs Baseline | Recommendation |
|---|---|---|---|
| Sorted Vector | 400.2μs | -4.7% | ⭐ Primary choice |
| Bitmask | 386.7μs | -7.9% | Fast for ≤64 scopes |
| Hybrid | 409.3μs | -2.5% | Not recommended |
| HashSet | 419.8μs | baseline | Reference |
Location: src/transducer/helpers.rs
Provides two optimized intersection implementations:
sorted_vec_intersection() - General-purpose O(n+m) two-pointer scanbitmask_intersection() - O(1) bitwise AND for ≤64 scopesTests: 9 comprehensive tests (all passing)
Location: examples/hierarchical_scope_completion.rs
Demonstrates:
Location: benches/hierarchical_scope_benchmarks.rs
For integration instructions and usage examples, see:
Hierarchical Scope Completion Guide
Topics covered:
Sorted vectors (contiguous memory) outperform hash tables due to better cache behavior, even with O(n+m) vs O(k) complexity.
Post-filtering is within 0.05% of early filtering, showing that graph traversal dominates query time.
Hybrid approaches with enum variants underperform due to branch misprediction and matching overhead.
For ≤64 scopes, bitmask approach provides 7.9% improvement with minimal memory (8 bytes per term).
CPU-level optimizations for sequential scans make sorted vector intersection very fast despite O(n+m) complexity.
Based on "Fast String Correction with Levenshtein-Automata" by Schulz & Mihov (2002):
Seamlessly integrates with existing query_filtered() API:
use liblevenshtein::prelude::*;
use liblevenshtein::transducer::helpers::sorted_vec_intersection;
let dict = PathMapDictionary::from_terms_with_values(terms);
let transducer = Transducer::new(dict, Algorithm::Standard);
let visible_scopes = vec![0, 1, 2];
let results: Vec<_> = transducer
.query_filtered("var", 2, |term_scopes| {
sorted_vec_intersection(term_scopes, &visible_scopes)
})
.map(|c| c.term)
.collect();
✅ Production-Ready:
Potential optimizations (not currently needed):
True Pruning: Store scope metadata on trie nodes
SIMD Acceleration: Vectorize array intersection
Adaptive Strategies: Runtime selection based on scope count
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |