Repository navigation
perf: 优化 tools 命令性能,缓存完整的工具列表结果 - #17
Merged
Merged
Conversation
问题: - tools 命令执行缓慢 - 同一个工具列表被请求了两次 1. getClient() 建立连接后调用 listTools() 缓存工具数量 2. /list 接口又调用一次 listTools() 获取完整信息 优化: - 将 toolsCache 从 Map<string, number> 改为 Map<string, any[]> - 缓存完整的 tools 结果而不仅仅是数量 - 新增 getCachedTools() 方法获取缓存的工具列表 - /list 接口优先使用缓存,避免重复调用 性能提升: - tools 命令从两次 listTools() 调用减少到零次(使用缓存) - 显著提升 tools 命令的响应速度 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
功能概述
优化 tools 命令的性能,通过缓存完整的工具列表结果,避免重复的 RPC 调用。
问题分析
性能问题:
调用链路:
tools命令 →DaemonClient.listTools()/list接口 →connectionPool.getClient()getClient()建立连接后调用listTools()(第一次),只缓存工具数量/list接口又调用client.listTools()(第二次) 获取完整信息优化方案
修改内容:
toolsCache从Map<string, number>改为Map<string, any[]>tools结果而不仅仅是数量getCachedTools()方法获取缓存的工具列表/list接口优先使用缓存,避免重复调用文件变更:
src/core/pool.ts- 缓存完整工具列表,新增 getCachedTools() 方法src/commands/daemon.ts- /list 接口优先使用缓存性能提升
优化前:
listTools()RPC 调用优化后:
listTools()RPC 调用(直接使用缓存)listTools()并缓存结果预期提升:
测试计划
🤖 Generated with Claude Code