Cache per-item token estimates across view_for_generation calls

オープン
#1,831 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
半日
初心者へのやさしさ
45/100
issue の種類
リファクタリング
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
performance

調査の方向性

Start with _as_list_token_budget in mellea/stdlib/context/chat.py and the per-call estimates dict, then trace how view_for_generation calls it. Decide whether the cache lives on the history thunk or is keyed by context version, since the issue leaves that open. Done means repeated views reuse the stored estimates without re-rendering or re-running json.dumps, which you can check with a timing or call-count test.

索引モデルが issue の本文から書いたものです。

説明

enhancement needs-design
What happened?

_as_list_token_budget (mellea/stdlib/context/chat.py, from #1760) renders
each history item through TemplateFormatter and, for tool-call replies,
re-serializes call args with json.dumps, to produce per-item token
estimates. The estimates dict only caches within a single call, but
view_for_generation runs 2–3× per generation (tool dispatch, backend
_generate_from_context, sampling retries), so a long tool-heavy history
re-renders the same spans and re-serializes the same tool calls repeatedly on
the generation hot path.

What did you expect to happen?

Since history items are immutable once added to the context, the per-item
estimate could be computed once — cached on the thunk, or memoized per
context version — making repeat views cheap.

Notes

Performance polish, not a correctness problem; only noticeable with long
tool-heavy histories. Follow-up from the #1760 review.

主要言語
Python
スター
1.8k
フォーク
161
平均マージ
4日 3時間
マージ済み PR(30日)
45

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

generative-computing/mellea のほかの issue

generative-computing/mellea の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。