mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-28 22:06:31 +00:00
fix(utils-cache): stop caching file contents above 1 MiB in read_text
read_text was an lru_cache over whole file contents. Whole-tree content scans also read the locale/*/LC_MESSAGES/docs.po catalogs (918 MiB on main), and every pytest-xdist worker that ran one kept them until it exited. Files above READ_TEXT_CACHE_MAX_BYTES (1 MiB) are now read fresh and never cached; every source file stays cached. Port of the cache hunks of 14d1fda59c (IAM line), byte-identical so the IAM merge stays conflict-free; its funkwhale test change stays on IAM. Measured on the 15 largest catalogs: VmRSS +482.7 MiB without the change, +0.1 MiB with it. 🎯 Fix: 92 % 💥 Break: 3 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 89 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
19c53260f6
commit
fdd915eaaf
2 files changed
+47
-5
No files matched your search
+15
@@ -72,6 +72,21 @@ class TestReadText(_ProjectRootFixture, unittest.TestCase):
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
read_text(str(self.root / "nope.txt"))
|
||||
|
||||
def test_file_above_the_cache_bound_is_never_cached(self) -> None:
|
||||
path = _touch(self.root / "catalog.po", "first")
|
||||
with patch.object(files_module, "READ_TEXT_CACHE_MAX_BYTES", 4):
|
||||
self.assertEqual(read_text(str(path)), "first")
|
||||
path.write_text("second", encoding="utf-8")
|
||||
self.assertEqual(read_text(str(path)), "second")
|
||||
self.assertEqual(files_module._read_cached.cache_info().currsize, 0)
|
||||
|
||||
def test_file_at_the_cache_bound_stays_cached(self) -> None:
|
||||
path = _touch(self.root / "a.txt", "four")
|
||||
with patch.object(files_module, "READ_TEXT_CACHE_MAX_BYTES", 4):
|
||||
self.assertEqual(read_text(str(path)), "four")
|
||||
path.write_text("zero", encoding="utf-8")
|
||||
self.assertEqual(read_text(str(path)), "four")
|
||||
|
||||
|
||||
class TestIterProjectFiles(_ProjectRootFixture, unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
|
||||
Reference in new issue
Block a user