feat(perf): enhance performance by improving disk caching and applying other optimizations #556
+2,263
−159
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 implements a comprehensive performance improvement plan that dramatically reduces Language Server startup time and improves edit responsiveness.
LibraryDocobjects to.robotcode_cache/*/resource/max_workers=min(cpu_count, 4))get_library_users()andget_variables_users()for instant change propagationTesting Plan
Architecture
Architecture Overview
flowchart TB subgraph cache["Disk Cache (.robotcode_cache/)"] lib["libdoc/<br/>Library docs"] res["resource/<br/>Resource docs"] ns["namespace/<br/>Namespace state"] end subgraph perf["Performance Optimizations"] p1["Shared Process Pool"] p2["Resource Caching"] p3["Targeted Invalidation"] p4["Parallel Library Loading"] p5["O(1) Dependency Lookups"] p7["Namespace Caching"] p9["Atomic Writes"] end subgraph maps["Reverse Dependency Maps"] imp["_importers<br/>source → documents"] lu["_library_users<br/>lib → documents"] vu["_variables_users<br/>var → documents"] end p1 --> lib p2 --> res p7 --> ns p9 --> ns p3 --> imp p5 --> lu p5 --> vuCold vs Warm Start Flow
flowchart TB subgraph startup["IDE Startup"] open["User Opens VS Code"] end subgraph cold["Cold Start (No Cache) ~2-4 min"] c1["Parse .robot files"] c2["Resolve imports in parallel"] c3["Load libraries<br/>(shared executor)"] c4["Build namespaces"] c5["Save to cache<br/>(atomic write)"] c1 --> c2 --> c3 --> c4 --> c5 end subgraph warm["Warm Start (Cache Hit) ~10-20 sec"] w1["Check .cache.pkl exists"] w2{"Validate:<br/>mtime + size?"} w3["Load (meta, spec)"] w4["Check environment identity"] w5["Restore namespace"] w1 --> w2 w2 -->|"Match"| w3 --> w4 --> w5 w2 -->|"Changed"| miss["Rebuild"] end subgraph runtime["Runtime Editing"] r1["File changed"] r2["O(1) lookup affected docs"] r3["Targeted invalidation"] r4["Rebuild only affected"] r1 --> r2 --> r3 --> r4 end open --> cold open --> warm style cold fill:#ffcccc,stroke:#cc0000 style warm fill:#ccffcc,stroke:#00cc00 style runtime fill:#cce5ff,stroke:#0066ccCache Validation Chain
sequenceDiagram participant LS as Language Server participant Cache as Disk Cache participant FS as File System Note over LS,FS: Warm Start Validation LS->>Cache: Load .cache.pkl Cache-->>LS: (meta, spec) tuple LS->>FS: stat(source_file) FS-->>LS: mtime, size alt mtime matches alt size matches Note over LS: Skip content hash!<br/>(Fast path) LS->>LS: Check python_executable LS->>LS: Check sys_path_hash alt Environment matches LS->>LS: Restore from cache ✓ else Environment changed LS->>LS: Rebuild namespace end else size differs LS->>FS: Read first+last 64KB FS-->>LS: content chunks LS->>LS: Compute tiered hash alt Hash matches LS->>LS: Restore from cache ✓ else Hash differs LS->>LS: Rebuild namespace end end else mtime differs LS->>LS: Rebuild namespace end