Commit 989f795
Shrink the deferred-reduction decision record
Measuring reducer-attributable peak memory (tracemalloc around the
_reduce call, four complex sentences) showed the deferred-reduction
decision record costing 3.8 MB against 1.4 MB for the previous
reduce-while-scoring approach. Notably, the early culling itself was
not what kept the old peak low - culled child nodes stay pinned as
visited-dict keys until go() returns regardless - the difference was
purely the size of the decision record.
Trim it in two ways. First, only the winning family's child list is
retained per (node, context); the losers' lists are never referenced
by the reduction pass (for no_reduce nonterminals, which the pass
descends into fully, the families are flattened into one list).
Second, an entry is only stored at all when the reduction pass cannot
infer it from the node: a real choice between multiple families, or
children scored under a context-sensitive signature. For the common
case - a single-family node whose children are all context-free - the
pass walks the node's own child list, deriving each child's signature
from its kind (None for tokens, NEUTRAL otherwise; the storage
condition guarantees these derivations match what the scoring pass
used).
Reducer-attributable peak drops to 2.1 MB on the same benchmark, with
byte-identical reduction output on the 30-sentence regression corpus
and unchanged wall time. 139 tests pass; mypy and ruff clean.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 0cb37d0 commit 989f795
1 file changed
Lines changed: 44 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
131 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
| |||
467 | 468 | | |
468 | 469 | | |
469 | 470 | | |
470 | | - | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
471 | 491 | | |
472 | 492 | | |
473 | 493 | | |
| |||
489 | 509 | | |
490 | 510 | | |
491 | 511 | | |
492 | | - | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
493 | 526 | | |
494 | | - | |
| 527 | + | |
495 | 528 | | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
| 529 | + | |
503 | 530 | | |
504 | | - | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
505 | 534 | | |
506 | | - | |
507 | | - | |
| 535 | + | |
| 536 | + | |
508 | 537 | | |
509 | 538 | | |
510 | 539 | | |
| |||
0 commit comments