Skip to content

perf: add LRU chunk-file cache to findEntity#1199

Open
jmountifield wants to merge 1 commit intomainfrom
feat/findEntity-lru-cache
Open

perf: add LRU chunk-file cache to findEntity#1199
jmountifield wants to merge 1 commit intomainfrom
feat/findEntity-lru-cache

Conversation

@jmountifield
Copy link
Copy Markdown

Summary

  • findEntity() for disk-resident entities reads and parses an entire JSON chunk file (~500 entities) on every call with no caching
  • Repeated lookups for entities in the same chunk file re-read and re-parse the file each time
  • Adds a bounded LRU cache (max 50 files) over chunk-file reads in FileSystemGraphObjectStore.findEntity()
  • Cache is invalidated on flushEntitiesToDisk() to prevent stale reads
  • Zero API changes — fully backwards compatible

Test plan

  • 4 new test cases covering cache hits, cross-entity cache sharing, cache invalidation on flush, and LRU eviction
  • All 29 existing FileSystemGraphObjectStore tests pass unchanged
  • Full runtime test suite (283 tests) passes
  • Pre-push hooks pass (lint + build:dist + test:changed)

🤖 Generated with Claude Code

When entities are flushed to disk, each findEntity() call reads and
parses an entire JSON chunk file (~500 entities) with no caching.
Repeated calls for entities in the same chunk file re-read the file
every time.

Add a bounded LRU cache (max 50 files) over chunk-file reads in
FileSystemGraphObjectStore.findEntity(). Second and subsequent lookups
for entities in the same chunk file are served from memory. Cache is
invalidated on flushEntitiesToDisk() to prevent stale reads.

Zero API changes — fully backwards compatible.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jmountifield jmountifield requested a review from a team as a code owner March 31, 2026 09:48
Copy link
Copy Markdown
Contributor

@VDubber VDubber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concerns:

  • adds complexity to SDK
  • adds memory consumption
  • A layer of caching is already implemented via localGraphObjectStore
  • time consuming to roll out and monitor for increased memory usage.
  • We already have an established pattern to move away from findEntity.

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.

2 participants