Commit 9bf0549
fix(kernel): key the window bounds cache on the window count as well as identity
Addresses two of the three review comments on this PR.
A window list that grows or shrinks in place keeps its id(), so identity alone was
not enough to decide a cache hit. run_prediction_kernel passes n_charge/n_export
from len(window_list) alongside the cached arrays, so a stale shorter array would
be read past its end by the C kernel - a memory-safety failure rather than merely
a wrong plan. The count is now part of the hit condition.
Nothing on the planning path resizes a window list today, so this guards the class
rather than fixing a live defect. The test proves it would have bitten: before the
change, appending to a cached list left a one-entry bounds array against two
windows, and popping left window_bound_tuple returning the longer tuple.
Also corrects the correctness note, which pointed at Plan.set_window_start() and
Prediction.set_window_start(). Neither exists - they are module functions here -
and after the rebase the prediction path does not use them at all, since
_prepare_export applies a trial start copy-on-write to a window dict and list of
its own.
The third comment, to build the bound tuple from a generator rather than a list
comprehension, is not taken: measured over 50k calls at 200 windows, the generator
is 19.3% slower (307ms against 366ms), because it pays per-item interpreter
overhead the specialised list comprehension avoids.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 4a0f828 commit 9bf0549
2 files changed
Lines changed: 39 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
401 | | - | |
402 | | - | |
403 | | - | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
404 | 405 | | |
405 | 406 | | |
406 | 407 | | |
| |||
457 | 458 | | |
458 | 459 | | |
459 | 460 | | |
460 | | - | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
461 | 468 | | |
462 | 469 | | |
463 | 470 | | |
464 | 471 | | |
465 | 472 | | |
466 | | - | |
| 473 | + | |
467 | 474 | | |
468 | 475 | | |
469 | 476 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
457 | 457 | | |
458 | 458 | | |
459 | 459 | | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
460 | 487 | | |
461 | 488 | | |
462 | 489 | | |
| |||
0 commit comments