CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

输入缓存命中率太低了

Open trytsomile opened this issue 6 months ago • 25 comments

对比同样被deepseek官方收录的DeepSeek-Reasonix的输入缓存命中率差了十万八千里,DeepSeek-Reasonix能达到百分之95+,这块急需改善

trytsomile avatar May 08 '26 08:05 trytsomile

Have u ever tried claude code with deepseek V4? Will the cache hit rate be higher?

ZJunSong avatar May 08 '26 08:05 ZJunSong

Have u ever tried claude code with deepseek V4? Will the cache hit rate be higher?

Used it before. Currently, DeepSeek-Reasonix has the highest input cache hit rate and saves the most tokens, followed by Claude Code.

trytsomile avatar May 08 '26 09:05 trytsomile

Have u ever tried claude code with deepseek V4? Will the cache hit rate be higher?

Used it before. Currently, DeepSeek-Reasonix has the highest input cache hit rate and saves the most tokens, followed by Claude Code.

Claude同样follow这个项目了 😉

AiurArtanis avatar May 08 '26 11:05 AiurArtanis

与opencode、deep code、Reasonix比,哪个编程效果最好?

ChangedenCZD avatar May 08 '26 12:05 ChangedenCZD

这里已经有一个关于缓存命中率低的 Issue:#1120

Rhapsody0x1 avatar May 08 '26 13:05 Rhapsody0x1

是的,使用claude cli和opencode缓存命中率经常能达到90%以上。期待deepseek tui的进化!

WEP-56 avatar May 08 '26 16:05 WEP-56

I have submitted an optimization regarding cache hit, you can check it out https://github.com/Hmbown/DeepSeek-TUI/pull/1196

wplll avatar May 08 '26 17:05 wplll

我觉得可以参考一下: https://github.com/esengine/DeepSeek-Reasonix/blob/main/docs/ARCHITECTURE.md

EGQM avatar May 09 '26 03:05 EGQM

This is a huge project, so I will take a while to handle it. The PR is being prepared now.

hxy91819 avatar May 09 '26 04:05 hxy91819

@hxy91819 建议在这个PR中,在右下角或者右上角增加一个cache hit的百分比显示。

Image

EGQM avatar May 09 '26 05:05 EGQM

@hxy91819 建议在这个PR中,在右下角或者右上角增加一个cache hit的百分比显示。

Image

今天分析了一下当前仓库的缓存命中情况,实际上有多个点位都存在需要优化的地方,为了稳定性考虑,我会多步去做优化。而且这个过程中还得建设一下评测机制。所以我说,这会是一个大工程。

我提交的第一个 PR 会从 MCP 相关的着手。这个目前看起来确定性非常高,不会产生任何功能变化、体验变化以及不容易产生回归。最容易优化。

至于 UI 显示层面,这个还是让 Maintainer 来定吧,我暂时还不会去动这一块。

hxy91819 avatar May 09 '26 12:05 hxy91819

I'd like to share some real-world data that confirms the low cache hit rate problem.

Data (same project, different tools)

Tool Total tokens Cache miss Hit rate
DeepSeek-TUI v0.8.12 ~1.4M ~180K 87.1%
WorkBuddy ~6M ~160K 97.3%
Image

Key observations

  • TUI's miss rate is ~4.8× higher (12.9% vs 2.7%)
  • If TUI were scaled to 6M tokens, estimated cache miss would be ~774K vs WorkBuddy's 160K — a gap of ~614K tokens
  • Compared to DeepSeek-Reasonix (95%+, mentioned above), 87.1% is indeed significantly lower

qinxianyuzou avatar May 09 '26 16:05 qinxianyuzou

Part 1 (MCP tool ordering): https://github.com/Hmbown/DeepSeek-TUI/pull/1319

Sorting determinism for the three non-deterministic sources in the MCP pipeline. Follow-up PRs will address conditional tool presence and other prefix-stability concerns.

hxy91819 avatar May 09 '26 16:05 hxy91819

@hxy91819 建议在这个PR中,在右下角或者右上角增加一个cache hit的百分比显示。 Image

今天分析了一下当前仓库的缓存命中情况,实际上有多个点位都存在需要优化的地方,为了稳定性考虑,我会多步去做优化。而且这个过程中还得建设一下评测机制。所以我说,这会是一个大工程。

我提交的第一个 PR 会从 MCP 相关的着手。这个目前看起来确定性非常高,不会产生任何功能变化、体验变化以及不容易产生回归。最容易优化。

至于 UI 显示层面,这个还是让 Maintainer 来定吧,我暂时还不会去动这一块。

Image 我在 #1196 的提交中添加了这个功能,并且优化了缓存命中

wplll avatar May 09 '26 16:05 wplll

@hxy91819 建议在这个PR中,在右下角或者右上角增加一个cache hit的百分比显示。

今天分析了一下当前仓库的缓存命中情况,实际上有多个点位都存在需要优化的地方,为了稳定性考虑,我会多步去做优化。而且这个过程中还得建设一下评测机制。所以我说,这会是一个大工程。 我提交的第一个 PR 会从 MCP 相关的着手。这个目前看起来确定性非常高,不会产生任何功能变化、体验变化以及不容易产生回归。最容易优化。 至于 UI 显示层面,这个还是让 Maintainer 来定吧,我暂时还不会去动这一块。 我在 #1196 的提交中添加了这个功能,并且优化了缓存命中

The new version is really good. I just ran a task that used more than 6 million tokens and hit 99.5% of the caches: 新版(deepseek 0.8.26 (c2893b9682ca)) 确实不错了。我刚才跑了一个任务,用了600多万 token,缓存命中 99.5%:

Image

哦,你的 pr 没合并呢是吧,那就是当前最新的版本是这样。

douglarek avatar May 10 '26 10:05 douglarek

我试了一下最新版0.8.26,平均命中率还是只有92%,这费用还是比较高 I tried the latest version 0.8.26, and the average hit rate is still only 92%, which is still relatively expensive.

Image

qinxianyuzou avatar May 10 '26 11:05 qinxianyuzou

我试了一下最新版0.8.26,平均命中率还是只有92%,这费用还是比较高 I tried the latest version 0.8.26, and the average hit rate is still only 92%, which is still relatively expensive.

这玩意除非有一个可复现的统一路径,感觉怎么跑都不可能完全一样,你看我上面跑了600多万花了不到8毛钱。对于这个问题的复现或者优化,建议一定要用deepseek官方服务,不要用第三方 deepseek v4 服务。

douglarek avatar May 10 '26 11:05 douglarek

我分享一个(另一个测试和上面那个 600w token 无关的仓库)我这边使用的几轮 turn 的过程,看看对这个问题有没有帮助: I'll share a (another test that has nothing to do with the 600w token repository above) a few rounds of turns that I use here, to see if it helps with this issue:

  1. 对话记录:https://gist.githubusercontent.com/douglarek/abece800e23791c59a9a8c812a878b4b/raw/6e784b922766848c0f6b5c3c52e2269b8afcf1de/deepseek-share-8oM3LM.html ,下载使用浏览器打开即可;
  2. /cache
      Note Cache telemetry — last 5 of 5 turn(s) (model: auto)
      ▏    ────────────────────────────────────────────────────────────────────────────
      ▏    turn   in    out   hit   miss   replay   ratio   age
      ▏    ────────────────────────────────────────────────────────────────────────────
      ▏    1  25839     12   4608  21231       —    17.8%   9m16s
      ▏    2  25906    288  25728    178       —    99.3%   8m58s
      ▏    3  264500   2528  235648  28852       —    89.1%   3m19s
      ▏    4  202230   3191  193536   8694       —    95.7%   52s
      ▏    5  45982    294  26112  19870       —    56.8%   11s
      ▏    ────────────────────────────────────────────────────────────────────────────
      ▏    Σ in: 564457   Σ hit: 485632   Σ miss: 78825   avg hit ratio: 86.0%
      ▏    - miss inferred from input − hit when the provider did not report it explicitly.
      ▏    Hit/miss ratios over ~70% after the third turn indicate a stable cache prefix; 
      ▏    lower than that on long sessions suggests prefix churn worth investigating (#263)
    

douglarek avatar May 10 '26 12:05 douglarek

我试了一下最新版0.8.26,平均命中率还是只有92%,这费用还是比较高 I tried the latest version 0.8.26, and the average hit rate is still only 92%, which is still relatively expensive.

这玩意除非有一个可复现的统一路径,感觉怎么跑都不可能完全一样,你看我上面跑了600多万花了不到8毛钱。对于这个问题的复现或者优化,建议一定要用deepseek官方服务,不要用第三方 deepseek v4 服务。

我是用的DeepSeek官方的服务,不是第三方的。我几乎不需要什么特别的路径,我搞几个很小的小项目,几乎每个都是这么低,而我用Claude相同的项目则能命中99% 所以我认为TUI的优化肯定是有问题的

qinxianyuzou avatar May 10 '26 14:05 qinxianyuzou

Code review 发现一个可能影响缓存命中率的因素:

SessionSource 和 ThreadStatus 在 protocol 和 state 两个 crate 重复定义,core crate 中有大量手动映射代码(to_protocol_thread, to_persisted_status, to_persisted_source 等)。如果映射逻辑导致消息格式或顺序不一致,DeepSeek API 的 prefix cache 匹配会失效。

另外 client/chat.rs 中 build_chat_messages_with_reasoning() 每次请求都大量 clone 消息结构,如果消息构建过程中有任何格式差异(空行、字段顺序、时间戳精度),都会导致 cache miss。

不过缓存命中率低更可能的原因是消息前缀不稳定 — 每轮对话的 system prompt 或前几条消息有任何变化都会导致整个 cache 失效。建议对比 DeepSeek-Reasonix 和本项目的实际发送 payload 差异。

punkcanyang avatar May 10 '26 15:05 punkcanyang