Repository navigation
fix(#412): the native bytes cache keeps no write parameters and no large text - #413
Merged
Merged
Conversation
…rge text lib.bc() remembered the UTF-8 of every text it saw for the first 4096 distinct texts, and the lazy command path of Database._exec passed the JSON text of the bound parameters through it, so a write of a large property kept the str and the bytes of its value for the life of the process (300 writes of 1 MiB: 696 MiB of growth, 600 MiB of it in the cache). The parameter text now goes through lib.b() as on the other paths, and bc() stores a text only when it has at most 1024 characters and the cache has fewer than 4096 entries; a longer text is encoded and returned without being hashed or stored.
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
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.
Closes #412
Thank you for reading the report so closely. This keeps the speed idea of
lib.bc()for the texts that repeat and stops it from keeping the value of a write.What changed:
Database._exec(lazy command path) passes the JSON text of the bound parameters throughlib.b(), as the other paths already do, instead oflib.bc(). That text is different on almost every write, so remembering it never helped.lib.bc()stores a text only when it has at most 1024 characters and the cache has fewer than 4096 entries. A longer text is encoded and returned without being hashed or stored. A statement text with a large literal in it is covered by the same bound.How I tested it: the new
tests/test_native_bytes_cache.py(native build only, listed intests/conftest.py) reads the cache content, not the resident set and not a time. It checks that a small text is cached and the hit returns the same bytes object, that the bound is 1024 characters (1025 is not stored), that the entry limit still holds, and that 100 writes of 256 KiB with new content each time (positional and named parameters, in a scratch database) leave only the statement texts inlib._bytes_cache, under 64 KiB in all. On the unfixed code 4 of the 6 tests fail (the database test finds 103 extra keys of about 256 KiB each, the parameter texts), with the fix all 6 pass. I ran them against the 26.12.1.dev0 native wheel (its_nativefiles are the ones onmain), unfixed and with the two changed files swapped in, on Python 3.14.Numbers from the repro of the issue (300 writes of 1 MiB, new content each time, same host and wheel, run once each):
lib._bytes_cacheI also checked the other module-level caches in
arcadedb/_native(records._EDGES_SQL,Database._type_kinds, the callback table): they are keyed by labels, type names or ids, not by values, and_EDGES_SQLis already capped at 512 entries, so I left them alone.The 1024 characters and the 4096 entries are my guess at "small", so please say if you would like a different bound.
🤖 Generated with Claude Code