Repository navigation
Commit d02f1b7
worker: cache aggregate const_args per execution_id
``_load_aggregate_const_args`` was hitting ``storage.aggregate_get([-2])``
on every aggregate_update / aggregate_window / aggregate_combine /
aggregate_finalize call — once per output row for windowed aggregates.
With the SQLite backend the read is microseconds and the cost is
invisible; with the CF Durable Object backend it's a ~60 ms HTTPS RTT
per call, so a 5000-row windowed query paid 300 s of round-trip just
re-reading values that never change.
Const args are written once at aggregate_bind (under group_id=-2) and
are immutable for the rest of the execution. Cache them per
``execution_id`` with a sentinel for the "no const args" negative case
(most aggregates) so we don't re-hit storage on every call.
Process-local LRU mirrors ``_WindowPartitionCache``'s shape: bounded
size (1024 entries), thread-safe via ``Lock``, cleared from
``aggregate_destructor`` alongside ``_window_partition_cache``.
Measured on ``aggregate/window.test`` (1 launcher worker, CF DO
storage in us-east):
before: 258 s (mostly per-row storage.aggregate_get on the 5000-row
multi-chunk partition test)
after: 14 s (~18× speedup; almost all remaining wall-clock is
the per-row ``aggregate_window`` worker RPC itself,
which is the right ceiling without a batched
worker-side path)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 915118a commit d02f1b7
1 file changed
Lines changed: 70 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
380 | 425 | | |
381 | 426 | | |
382 | 427 | | |
| |||
1725 | 1770 | | |
1726 | 1771 | | |
1727 | 1772 | | |
1728 | | - | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
1729 | 1782 | | |
1730 | 1783 | | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
1731 | 1790 | | |
1732 | | - | |
1733 | | - | |
1734 | | - | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
1735 | 1800 | | |
1736 | 1801 | | |
1737 | 1802 | | |
| |||
2051 | 2116 | | |
2052 | 2117 | | |
2053 | 2118 | | |
| 2119 | + | |
2054 | 2120 | | |
2055 | 2121 | | |
2056 | 2122 | | |
| |||
0 commit comments