You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hatch::configure re-read and re-parsed pyproject.toml + hatch.toml for every workspace folder on every call. In the v1.33 insiders regression report, this per-call I/O (run while holding the configuration write lock) was the largest single amplifier of the cross-platform pet.refresh p90 regression.
Changes
Per-workspace TOML cache in pet-hatch, keyed by (workspace_path, pyproject_mtime, hatch_toml_mtime). Cached entries are reused when both file mtimes are unchanged; missing files are recorded as None mtime so deletions invalidate correctly.
configure() is now stat-only on warm cache — O(workspace_count) stats instead of O(workspace_count × 2) reads + parses. Cold path is unchanged.
Cache lives behind the existing workspace_virtual_dirs mutex, so no new locking surface is introduced and ordering vs. lookups is preserved.
Tests covering cache hit on unchanged mtimes, invalidation on TOML edit, invalidation on file deletion/creation, and behavior across multiple workspace folders.
Notes for reviewers
Mtime resolution can be coarse on some filesystems (FAT, some network mounts). If a TOML is rewritten within the same mtime tick, the cache will return stale data until the next change. Calling out explicitly since this matches the issue's proposed design but is worth confirming acceptable.
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds an mtime-keyed parse cache to the Hatch locator so repeated configure() calls skip re-reading and re-parsing pyproject.toml/hatch.toml when those files are unchanged, addressing a pet.refresh p90 regression.
Changes:
Introduces CachedWorkspaceConfig / ParsedCache and a parsed_cache field on Hatch, keyed by workspace path with (pyproject_mtime, hatch_toml_mtime) validation.
Rewrites configure() to stat the two TOML files per workspace and reuse parsed results on a warm cache; cold path falls back to the existing parse.
Adds tests for cache reuse, mtime-based invalidation, file-appearance invalidation, and eviction of dropped workspaces.
Show a summary per file
File
Description
crates/pet-hatch/src/lib.rs
Adds per-workspace mtime-keyed parse cache, updates configure() to use it, updates test helpers, and adds 4 cache tests.
Cache strategy is right: stat-only warm path, None mtime treated as a value so absence/presence transitions invalidate, eviction by rebuild rather than tombstones.
Two things to address before merge:
Publish atomicity — workspace_virtual_dirs and parsed_cache are assigned under separate locks. Wrap both publishes in one critical section, or document why the brief out-of-sync window is safe (only workspace_virtual_dirs is read by try_from, so external observers can't see the half-update).
TOCTOU comment — the "self-healing under TOCTOU" line overstates the guarantee. On coarse-mtime filesystems, two writes in the same tick won't bump the mtime; the stored value will then equal what the next configure observes and the stale parse will persist. Suggest softening to "the next configure with an updated mtime will re-parse" and leave the existing struct-level doc as the authoritative caveat.
On scope: keeping this Hatch-specific is correct. Every other locator's configure() is O(1) lock writes with no I/O, so there's nothing to cache there. Detecting Hatch before caching would require reading the exact files we're trying not to read — counterproductive.
Addressed in 36c901c: documented why the separate cache publishes are externally safe and softened the TOCTOU comment to only guarantee re-parse when a later configure observes an updated mtime.
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
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.
Hatch::configurere-read and re-parsedpyproject.toml+hatch.tomlfor every workspace folder on every call. In the v1.33 insiders regression report, this per-call I/O (run while holding the configuration write lock) was the largest single amplifier of the cross-platformpet.refreshp90 regression.Changes
pet-hatch, keyed by(workspace_path, pyproject_mtime, hatch_toml_mtime). Cached entries are reused when both file mtimes are unchanged; missing files are recorded asNonemtime so deletions invalidate correctly.configure()is now stat-only on warm cache —O(workspace_count)stats instead ofO(workspace_count × 2)reads + parses. Cold path is unchanged.workspace_virtual_dirsmutex, so no new locking surface is introduced and ordering vs. lookups is preserved.Notes for reviewers
mainafter fix(#461): release configuration write lock around locator.configure() #466 merged; this PR no longer touchesjsonrpc.rs.