Overview
Every invocation of scan() re-parses all target .sol files from scratch, even when files have not changed since the last scan. In the VS Code extension use case (scan-on-save), this means the entire workspace is re-parsed on every keystroke-triggered save, which is wasteful and adds perceptible latency on large projects.
Problem
For a project with 50 Solidity files, a full workspace scan re-parses all 50 files even if only 1 changed. The @solidity-parser/parser is fast, but at scale (e.g. a large DeFi protocol with 100+ contracts and inheritance chains), this becomes the dominant cost in the scan pipeline.
Measured impact in benchmarks:
- 10 files: ~40ms parse time (acceptable)
- 50 files: ~200ms parse time (noticeable)
- 100+ files: ~500ms+ parse time (degrades UX)
Proposed Solution
Implement a content-addressed AST cache with the following design:
interface ASTCacheEntry {
contentHash: string; // SHA-256 of file contents
ast: ASTNode;
parsedAt: number; // timestamp
filePath: string;
}
- Before parsing, compute SHA-256 of file content
- Check an in-memory LRU cache (bounded to 200 entries) for a matching hash
- On cache hit, return cached AST — skip
@solidity-parser/parser entirely
- On cache miss, parse and store in cache
- In the VS Code extension, persist cache to
globalStorageUri across sessions
- Expose a
clearCache() export from @chainproof/core for testing and forced refresh
Performance Target
- Re-scan of unchanged workspace: >80% reduction in parse time
- Single changed file scan: cache hit for all other files, only changed file re-parsed
Acceptance Criteria
Overview
Every invocation of
scan()re-parses all target.solfiles from scratch, even when files have not changed since the last scan. In the VS Code extension use case (scan-on-save), this means the entire workspace is re-parsed on every keystroke-triggered save, which is wasteful and adds perceptible latency on large projects.Problem
For a project with 50 Solidity files, a full workspace scan re-parses all 50 files even if only 1 changed. The
@solidity-parser/parseris fast, but at scale (e.g. a large DeFi protocol with 100+ contracts and inheritance chains), this becomes the dominant cost in the scan pipeline.Measured impact in benchmarks:
Proposed Solution
Implement a content-addressed AST cache with the following design:
@solidity-parser/parserentirelyglobalStorageUriacross sessionsclearCache()export from@chainproof/corefor testing and forced refreshPerformance Target
Acceptance Criteria
ASTCacheclass implemented inpackages/core/src/ast/cache.tscontext.globalStorageUriclearCache()exported from@chainproof/core