Skip to content

Feat/lint cache and stdin#540

Open
AlexCannonball wants to merge 2 commits intoyoheimuta:masterfrom
AlexCannonball:feat/lint-cache-and-stdin
Open

Feat/lint cache and stdin#540
AlexCannonball wants to merge 2 commits intoyoheimuta:masterfrom
AlexCannonball:feat/lint-cache-and-stdin

Conversation

@AlexCannonball
Copy link
Copy Markdown
Contributor

@AlexCannonball AlexCannonball commented Mar 8, 2026

Summary:

Addresses #443

The majority of time is spent parsing

This PR introduces support for linting from stdin and significantly improves performance for linting by implementing an in-memory AST cache.

Key Improvements:

Performance (~7.2x faster): By caching the parsed AST and raw file content, we eliminated redundant disk I/O and parsing cycles.

Benchmark (googleapis/google/ads, WSL + Ubuntu): Master: 54s → This PR: 7.5s.

Benchmarking script
#!/bin/bash
BINARY=$1
# We use the relative path to the google folder
TARGET_DIR="./ads/"

echo "Benchmarking: $BINARY"

for i in {1..3}; do
  echo -n "Run $i: "
  # We use 'time' and redirect output to /dev/null to see only the speed
  { time $BINARY lint $TARGET_DIR > /dev/null 2>&1; } 2>&1 | grep real
done
image

Virtual File System (VFS): Implemented a thread-safe, memory-first VFS wrapper (file.Open, file.ReadFile). This allows rules to access stdin content or "shadow" disk files without physical file handles.

LSP Ready: The architecture is now thread-safe (using sync.RWMutex) and supports virtual filenames, making it good for future Language Server Protocol (LSP) integrations.

MCP can potentially benefit from piping file buffers directly into the linter. This enables faster, more secure "lint-as-you-type" or "AI-fix" workflows without the overhead of temporary file management.

WASM Readiness:
This refactoring prepares protolint for high-performance WebAssembly (WASI) execution. By implementing a memory-first VFS and single-pass parsing, we've eliminated the costly I/O overhead typical in WASM runtimes.

I've also tested it in my LSP draft. This optimization brings WASM linting time for a ~600 line file down from 250+ms to ~54ms, making real-time IDE integration viable.

Robust Validation: Implemented fail-fast guards to prevent incompatible flag combinations (like -fix with stdin).

Technical Details:

  • Changed ProtoFile to a pointer-based receiver to maintain state across the linter lifecycle.
  • Added cachedData and cachedProto fields to avoid re-parsing for each of the rules.

@AlexCannonball AlexCannonball force-pushed the feat/lint-cache-and-stdin branch 2 times, most recently from 8449901 to 01ecd64 Compare March 11, 2026 18:49
@AlexCannonball AlexCannonball force-pushed the feat/lint-cache-and-stdin branch from 01ecd64 to 7996816 Compare March 11, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant