-
Notifications
You must be signed in to change notification settings - Fork 66
feat(tidy3d): FXC-3902-make-manipulations-on-local-cache-more-performant #2945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yaugenst-flex
merged 1 commit into
develop
from
FXC-3902-make-manipulations-on-local-cache-more-performant
Nov 5, 2025
Merged
feat(tidy3d): FXC-3902-make-manipulations-on-local-cache-more-performant #2945
yaugenst-flex
merged 1 commit into
develop
from
FXC-3902-make-manipulations-on-local-cache-more-performant
Nov 5, 2025
Conversation
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 6 comments
Contributor
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
tidy3d/web/cache.py |
b077d1c to
149a936
Compare
39c81d8 to
2113337
Compare
2113337 to
5166930
Compare
5166930 to
e3361d4
Compare
yaugenst-flex
approved these changes
Nov 5, 2025
Collaborator
yaugenst-flex
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.
Issue
LocalCache._iter_entriesis used when storing new data in the cache. This will be inefficient for many simulations. We should track changes and hold a file reflecting statistics like storage size and no. of simulations.PR
_store,_touch,_remove_entryand_clearLocalCache._iter_entriesis now a generatorGreptile Overview
Updated On: 2025-10-30 17:09:35 UTC
Greptile Summary
Implements a
stats.jsonfile to track cache metadata (entry count, total size, last access times) to avoid iterating all cache entries during store/eviction operations, significantly improving performance for large caches.Key Changes:
CacheStatspydantic model to represent the stats file structure_iter_entries()from returning a list to yielding entries (generator pattern)_record_store_stats(),_record_touch_stats(), and_record_remove_stats()to update stats incrementallysync_stats()method to rebuild stats from filesystem when inconsistencies are detected__len__()to read from stats instead of iterating entries_ensure_limits()to calculate projected size/count before evictionIssues Found:
_record_*_stats()methods where negativetotal_sizetriggerssync_stats()but returns early without writing the updatedentriesdict, leaving stats in an inconsistent state_touch()early return path whenfile_sizeis missing_store()where_load_entry()is called inside a lock but doesn't use locking itselfreclaimed)Confidence Score: 2/5
total_sizegoes negative. These bugs will lead to stats.json becoming out of sync with the actual cache state. Additionally, there's a potential race condition and an eviction bug that could prevent proper cache size management.tidy3d/web/cache.py, specifically the_record_store_stats,_record_touch_stats,_record_remove_stats,_touch, and_evict_by_sizemethodsImportant Files Changed
File Analysis
stats.jsonto track cache metadata for performance but has critical logic bugs in stats update methods that cause incomplete writes whentotal_sizegoes negative, and a race condition in_store_iter_entriesis not called during store/fetch operationsSequence Diagram
sequenceDiagram participant Client participant LocalCache participant StatsJSON as stats.json participant FileSystem as File System Note over Client,FileSystem: Store Operation Client->>LocalCache: _store(key, source_path, metadata) LocalCache->>LocalCache: _lock acquired LocalCache->>LocalCache: _load_entry(key) - check existing LocalCache->>StatsJSON: _load_stats() StatsJSON-->>LocalCache: current stats LocalCache->>LocalCache: _ensure_limits(file_size, incoming_key, replacing_size) LocalCache->>StatsJSON: _load_stats() - check limits StatsJSON-->>LocalCache: stats for eviction check alt Eviction needed LocalCache->>LocalCache: _evict() or _evict_by_size() loop For each candidate LocalCache->>FileSystem: _remove_entry(entry) LocalCache->>StatsJSON: _record_remove_stats(key, file_size) end end LocalCache->>FileSystem: copy artifact to cache LocalCache->>StatsJSON: _record_store_stats(key, last_used, file_size, previous_size) StatsJSON->>StatsJSON: update last_used[key], total_size LocalCache->>LocalCache: _lock released LocalCache-->>Client: CacheEntry Note over Client,FileSystem: Fetch Operation Client->>LocalCache: _fetch(key) LocalCache->>LocalCache: _lock acquired LocalCache->>LocalCache: _load_entry(key) LocalCache->>FileSystem: read metadata.json FileSystem-->>LocalCache: entry metadata LocalCache->>LocalCache: verify() - checksum alt Valid entry LocalCache->>LocalCache: _touch(entry) LocalCache->>FileSystem: update metadata.json LocalCache->>StatsJSON: _record_touch_stats(key, last_used, file_size) LocalCache-->>Client: CacheEntry else Invalid/missing LocalCache-->>Client: None end LocalCache->>LocalCache: _lock released Note over Client,FileSystem: Sync Stats Recovery Client->>LocalCache: sync_stats() LocalCache->>LocalCache: _lock acquired, _syncing_stats = True LocalCache->>LocalCache: _iter_entries() - scan all loop For each entry LocalCache->>FileSystem: read metadata.json FileSystem-->>LocalCache: file_size, last_used end LocalCache->>StatsJSON: _write_stats(rebuilt) StatsJSON->>StatsJSON: persist complete stats LocalCache->>LocalCache: _syncing_stats = False, _lock released LocalCache-->>Client: CacheStats