Open
Conversation
8449901 to
01ecd64
Compare
01ecd64 to
7996816
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Addresses #443
This PR introduces support for linting from
stdinand 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
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
protolintfor 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
-fixwithstdin).Technical Details:
ProtoFileto a pointer-based receiver to maintain state across the linter lifecycle.cachedDataandcachedProtofields to avoid re-parsing for each of the rules.