Files
hermes-agent/tests
Adolanium c40655ebb6 perf(moa): weigh reference trim once per message instead of re-estimating per pop
The reference context-fit loop re-ran estimate_messages_tokens_rough on
head + body after every pop, paying one full memo walk per dropped
frame (O(n^2) on long histories). The estimator is a pure sum of
per-message weights, so weigh each message once, track a running
total, and subtract on pop. The pop sequence is unchanged and the trim
result is identical to the naive loop, pinned by a randomized
equivalence test against the original implementation plus an O(n)
estimator-call-count guard.

n=502 advisory frames trimmed to 106: 100.8ms -> 0.9ms per call.

cherry-picked-from: 226a8786f2cba9380be930d28604c81880d3f6f7
2026-09-23 21:28:38 +05:30
..