Repository navigation
Cache stale_counts on a store change counter (per-command cost flat in session size) - #255
Merged
Merged
Conversation
…scan MemStore.change_count (MemStore._version + RecordTable.version) is bumped by every mutator. housekeep.stale_counts caches its result on the MemStore keyed on it, so a read command does no scan and the first command after a write rescans once. @wrn output is unchanged. Tests enumerate MemStore/RecordTable methods and fail when a new one is not classified as mutator (bumps) or reader.
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.
Why
Owner goal: per-command cost must not grow with session size, since sessions are uncapped (t1014s4254). Every command goes through
cli._load_session->emit_stale_warnings->stale_counts, which scanned every row each time (about 97% of the size-dependent cost; see findings).What
mem_store.py:MemStore.change_count(MemStore._version+RecordTable.version). Every mutator bumps it: allRecordTabledict mutators and index helpers, andMemStoreload, upsert, delete, restore, rename, reindex, index/unindex of tag and edge, high-water raise,mark_dirty.housekeep.py:stale_countscaches its result on theMemStore(so keyed on store identity) with the counter. Reads skip the scan; the first command after a write rescans once.use_cache=Falseforces the scan.@WRNoutput is unchanged.upgrade.py,serve.py,serve_pool.pyandsysml-modelsare untouched.Tests
tests/test_stale_scan_cache.py:test_warnings_identical_across_writes_deletes_edges_recycle,test_warnings_identical_through_cli_commands,test_read_skips_scan_write_rescans_once,test_cache_is_per_storetest_every_memstore_method_is_classified,test_every_recordtable_method_is_classified(a new method must be listed as mutator or reader),test_memstore_mutator_bumps_change_count[*],test_recordtable_mutator_bumps_version[*],test_readers_leave_change_count_alone,test_state_change_always_bumpstest_read_command_time_flat_in_session_size(find at 5k within 1.5x of 1k; fails with the cache disabled)Full
pytestpasses locally;ruff checkandruff format --checkclean on the CI paths.Numbers
Same machine, ms per command (
prof2.py):