JS-1001 Add unified filesystem cache module #6086
Open
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
This PR introduces a new filesystem cache module (
packages/shared/src/fs-cache/) that intercepts ALL filesystem operations, including those from dependencies like TypeScript and ESLint. The cache uses a unified tree structure for efficient storage and supports disk persistence via protobuf serialization.Key Features
fsmodule to cache all filesystem operationsFsNodedata structure represents all cached path informationDesign Decisions Explored
1. Unified Tree vs Separate Maps
Initially considered separate
Maps for each operation type (files, directories, stats, etc.). Chose unifiedFsNodestructure because:2. Cache Lookup Result Pattern
Implemented
CacheLookupResult<T>to distinguish three states:undefinedreturned: path not in cache (cache miss){ exists: false }: cached knowledge that path doesn't exist{ exists: true, value: T }: cached data for existing path3. opendir/opendirSync Caching
fs.opendirreturns aDirobject (async iterator). ImplementedCachedDirclass that:Dirinterface includingSymbol.asyncDispose/Symbol.dispose4. Type Reuse
Reuses
@types/nodetypes where possible viaPick<Stats, ...>instead of maintaining custom type definitions.Files Created
cache-types.tsFsNode,FsNodeStat,CacheStats)cache-utils.tsproject-cache.tscache-manager.tsfs-patch.tsCachedDirclassindex.tsproto/fs-cache.protoproto/fs-cache.jsproto/fs-cache.d.tsCached Operations
readFileSync/readFilereaddirSync/readdir(withwithFileTypessupport)statSync/statlstatSync/lstatexistsSyncrealpathSync/realpathaccessSync/accessopendirSync/opendirNext Steps for Integration
Initialize at startup: Call
initFsCache()when gRPC/HTTP server startsSet active project before analysis: Call
setActiveProject()with project infoLoad cache from previous run (optional):
Save cache after analysis:
Add cache invalidation: Implement file watcher or use Sonar's file change detection to call
invalidatePath()when files changeAdd tests: Unit tests for cache operations, integration tests for fs patching
Performance metrics: Use
getFsCacheStats()to measure cache effectiveness🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com