query-cascade 0.3.17__tar.gz → 0.3.18__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {query_cascade-0.3.17 → query_cascade-0.3.18}/PKG-INFO +20 -1
- {query_cascade-0.3.17 → query_cascade-0.3.18}/README.md +19 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/pyproject.toml +1 -1
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/_disk_cache.py +9 -5
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/query_cascade.egg-info/PKG-INFO +20 -1
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_disk_cache.py +30 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/setup.cfg +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/__init__.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/_ast_rewrite.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/_canonical.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/_collections.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/_errors.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/_evaluator.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/_graph_export.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/_incremental.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/_persistence.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/_runtime.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/_scheduler.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/_serde.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/_state.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/_store.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/_synthetic_graph.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/cascade/engine.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/query_cascade.egg-info/SOURCES.txt +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/query_cascade.egg-info/dependency_links.txt +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/query_cascade.egg-info/requires.txt +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/src/query_cascade.egg-info/top_level.txt +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_ast_rewrite.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_async.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_async_coverage.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_code_versioning.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_datetime.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_dependency_parallelism.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_engine.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_engine_compute_many.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_engine_concurrency.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_engine_persistence_and_tracing.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_engine_private.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_engine_private2.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_engine_sweep.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_error_caching.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_error_caching_persistence.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_evaluator_and_synthetic_coverage.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_examples.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_fixed_point.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_incremental_collections.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_incremental_graph.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_incremental_persistence.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_incremental_pipeline.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_internal_invariants.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_memoize_false.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_performance.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_repro_touch_memo_keyerror.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_scale_behavior.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_serde.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_stateful_engine_invariants.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_store_coverage.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_subgraph_stats_export.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_sweep_unaccessed.py +0 -0
- {query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_ttl.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: query-cascade
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.18
|
|
4
4
|
Summary: Minimal demand-driven query framework for incremental computation.
|
|
5
5
|
Requires-Python: >=3.12
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -305,6 +305,25 @@ Rewriting covers comprehensions (`[...]`, `{...}`, `{k: v ...}`), `map`, `filter
|
|
|
305
305
|
* `enumerate()` and `zip()` sources are explicitly excluded.
|
|
306
306
|
* Opt out globally via `Engine(incremental=False)` or per-query `@engine.query(incremental=False)`.
|
|
307
307
|
|
|
308
|
+
### Batching Mutations for Disk Performance
|
|
309
|
+
|
|
310
|
+
By design, Cascade collections use an immediate write-ahead pattern for crash-safety. Every time you mutate a collection (`__setitem__`, `append()`, `add()`), Cascade immediately opens a disk transaction, writes the diff to the MDBX event log, and forces an OS sync (`fsync`).
|
|
311
|
+
|
|
312
|
+
If you iterate through a loop inserting thousands of records one by one, you will trigger thousands of physical disk syncs, resulting in extremely slow performance (e.g., waiting on disk I/O).
|
|
313
|
+
|
|
314
|
+
To avoid this, always align disk syncs with your **logical units of work** by batching bulk-inserts using `.update()` or `extend()`. This allows Cascade to group all changes into a single disk transaction:
|
|
315
|
+
|
|
316
|
+
```python
|
|
317
|
+
# SLOW (10,000 separate disk syncs)
|
|
318
|
+
for i in range(10000):
|
|
319
|
+
docs[f"doc_{i}"] = i
|
|
320
|
+
|
|
321
|
+
# FAST (1 single disk sync)
|
|
322
|
+
docs.update({f"doc_{i}": i for i in range(10000)})
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
*(Note: `.update()` behaves exactly like a standard Python dictionary. If a key already exists, it will seamlessly overwrite the old value by batching an `"upsert"` event to the underlying log, ensuring downstream queries receive the correct diffs.)*
|
|
326
|
+
|
|
308
327
|
### Persistence & Inspection
|
|
309
328
|
|
|
310
329
|
A **named** collection on an engine with `cache_dir` event-sources its log to disk automatically.
|
|
@@ -286,6 +286,25 @@ Rewriting covers comprehensions (`[...]`, `{...}`, `{k: v ...}`), `map`, `filter
|
|
|
286
286
|
* `enumerate()` and `zip()` sources are explicitly excluded.
|
|
287
287
|
* Opt out globally via `Engine(incremental=False)` or per-query `@engine.query(incremental=False)`.
|
|
288
288
|
|
|
289
|
+
### Batching Mutations for Disk Performance
|
|
290
|
+
|
|
291
|
+
By design, Cascade collections use an immediate write-ahead pattern for crash-safety. Every time you mutate a collection (`__setitem__`, `append()`, `add()`), Cascade immediately opens a disk transaction, writes the diff to the MDBX event log, and forces an OS sync (`fsync`).
|
|
292
|
+
|
|
293
|
+
If you iterate through a loop inserting thousands of records one by one, you will trigger thousands of physical disk syncs, resulting in extremely slow performance (e.g., waiting on disk I/O).
|
|
294
|
+
|
|
295
|
+
To avoid this, always align disk syncs with your **logical units of work** by batching bulk-inserts using `.update()` or `extend()`. This allows Cascade to group all changes into a single disk transaction:
|
|
296
|
+
|
|
297
|
+
```python
|
|
298
|
+
# SLOW (10,000 separate disk syncs)
|
|
299
|
+
for i in range(10000):
|
|
300
|
+
docs[f"doc_{i}"] = i
|
|
301
|
+
|
|
302
|
+
# FAST (1 single disk sync)
|
|
303
|
+
docs.update({f"doc_{i}": i for i in range(10000)})
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
*(Note: `.update()` behaves exactly like a standard Python dictionary. If a key already exists, it will seamlessly overwrite the old value by batching an `"upsert"` event to the underlying log, ensuring downstream queries receive the correct diffs.)*
|
|
307
|
+
|
|
289
308
|
### Persistence & Inspection
|
|
290
309
|
|
|
291
310
|
A **named** collection on an engine with `cache_dir` event-sources its log to disk automatically.
|
|
@@ -37,13 +37,17 @@ _FT_LOCK = threading.RLock()
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
class TxnContext:
|
|
40
|
-
def __init__(self,
|
|
41
|
-
self.
|
|
40
|
+
def __init__(self, env: Any, write: bool, kwargs: dict[str, Any]) -> None:
|
|
41
|
+
self.env = env
|
|
42
42
|
self.write = write
|
|
43
|
+
self.kwargs = kwargs
|
|
44
|
+
self.txn: Any = None
|
|
43
45
|
|
|
44
46
|
def __enter__(self) -> Any:
|
|
45
47
|
if _FREE_THREADED:
|
|
46
48
|
_FT_LOCK.acquire() # pragma: no cover
|
|
49
|
+
flags = 0 if self.write else mdbx.MDBXTXNFlags.MDBX_TXN_RDONLY
|
|
50
|
+
self.txn = self.env.start_transaction(flags=flags, **self.kwargs)
|
|
47
51
|
return self.txn.__enter__()
|
|
48
52
|
|
|
49
53
|
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> Any:
|
|
@@ -158,9 +162,7 @@ class DiskCache:
|
|
|
158
162
|
return self._env.get_path()
|
|
159
163
|
|
|
160
164
|
def _begin(self, write: bool = False, **kwargs: Any) -> Any:
|
|
161
|
-
|
|
162
|
-
txn = self._env.start_transaction(flags=flags, **kwargs)
|
|
163
|
-
return TxnContext(txn, write)
|
|
165
|
+
return TxnContext(self._env, write, kwargs)
|
|
164
166
|
|
|
165
167
|
def _ensure_format(self) -> None:
|
|
166
168
|
stamp = DISK_FORMAT.to_bytes(4, "big")
|
|
@@ -281,6 +283,8 @@ class DiskCache:
|
|
|
281
283
|
break
|
|
282
284
|
if int.from_bytes(kb[len(prefix) :], "big") <= upto_rev:
|
|
283
285
|
drop.append(kb)
|
|
286
|
+
else:
|
|
287
|
+
break
|
|
284
288
|
for key in drop:
|
|
285
289
|
self._collections.delete(txn, key)
|
|
286
290
|
except mdbx.MDBXErrorExc as exc:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: query-cascade
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.18
|
|
4
4
|
Summary: Minimal demand-driven query framework for incremental computation.
|
|
5
5
|
Requires-Python: >=3.12
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -305,6 +305,25 @@ Rewriting covers comprehensions (`[...]`, `{...}`, `{k: v ...}`), `map`, `filter
|
|
|
305
305
|
* `enumerate()` and `zip()` sources are explicitly excluded.
|
|
306
306
|
* Opt out globally via `Engine(incremental=False)` or per-query `@engine.query(incremental=False)`.
|
|
307
307
|
|
|
308
|
+
### Batching Mutations for Disk Performance
|
|
309
|
+
|
|
310
|
+
By design, Cascade collections use an immediate write-ahead pattern for crash-safety. Every time you mutate a collection (`__setitem__`, `append()`, `add()`), Cascade immediately opens a disk transaction, writes the diff to the MDBX event log, and forces an OS sync (`fsync`).
|
|
311
|
+
|
|
312
|
+
If you iterate through a loop inserting thousands of records one by one, you will trigger thousands of physical disk syncs, resulting in extremely slow performance (e.g., waiting on disk I/O).
|
|
313
|
+
|
|
314
|
+
To avoid this, always align disk syncs with your **logical units of work** by batching bulk-inserts using `.update()` or `extend()`. This allows Cascade to group all changes into a single disk transaction:
|
|
315
|
+
|
|
316
|
+
```python
|
|
317
|
+
# SLOW (10,000 separate disk syncs)
|
|
318
|
+
for i in range(10000):
|
|
319
|
+
docs[f"doc_{i}"] = i
|
|
320
|
+
|
|
321
|
+
# FAST (1 single disk sync)
|
|
322
|
+
docs.update({f"doc_{i}": i for i in range(10000)})
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
*(Note: `.update()` behaves exactly like a standard Python dictionary. If a key already exists, it will seamlessly overwrite the old value by batching an `"upsert"` event to the underlying log, ensuring downstream queries receive the correct diffs.)*
|
|
326
|
+
|
|
308
327
|
### Persistence & Inspection
|
|
309
328
|
|
|
310
329
|
A **named** collection on an engine with `cache_dir` event-sources its log to disk automatically.
|
|
@@ -862,3 +862,33 @@ def test_deep_dependency_chain_cross_session(tmp_path: Path) -> None:
|
|
|
862
862
|
assert chain_3(49) == 60
|
|
863
863
|
assert len(runs) == 50
|
|
864
864
|
engine_3.shutdown()
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
def test_collection_snapshot_does_not_scan_entire_log(
|
|
868
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
869
|
+
) -> None:
|
|
870
|
+
cache = tmp_path / "cache"
|
|
871
|
+
disk = disk_cache_mod.DiskCache(cache, map_size=1 << 24)
|
|
872
|
+
name = "test_col"
|
|
873
|
+
|
|
874
|
+
diffs = [(i, {"diff": i}) for i in range(1, 11)]
|
|
875
|
+
disk.collection_append_many(name, diffs)
|
|
876
|
+
|
|
877
|
+
iterations = 0
|
|
878
|
+
import mdbx
|
|
879
|
+
|
|
880
|
+
original_iter = mdbx.Cursor.iter
|
|
881
|
+
|
|
882
|
+
def mocked_iter(self, start_key=None):
|
|
883
|
+
nonlocal iterations
|
|
884
|
+
for key, value in original_iter(self, start_key=start_key):
|
|
885
|
+
iterations += 1
|
|
886
|
+
yield key, value
|
|
887
|
+
|
|
888
|
+
monkeypatch.setattr(mdbx.Cursor, "iter", mocked_iter)
|
|
889
|
+
|
|
890
|
+
disk.collection_snapshot(name, {"snap": True}, upto_rev=5)
|
|
891
|
+
|
|
892
|
+
# Revisions 1 through 5, plus revision 6 which breaks the loop
|
|
893
|
+
assert iterations == 6
|
|
894
|
+
disk.close()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{query_cascade-0.3.17 → query_cascade-0.3.18}/src/query_cascade.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{query_cascade-0.3.17 → query_cascade-0.3.18}/tests/test_evaluator_and_synthetic_coverage.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|