Skip to content

perf(core): optimize agent runtime event processing #137

Description

@HayWolf

来源

PR #136 review 评估后续跟进项

涉及的 review comments

#1 — agent_session_events.rs:71 — ThinkingDelta 每次 clone 完整 reasoning buffer (O(n2))

每个 ThinkingDelta 事件都 buffer.clone() 发送 ReasoningUpdated,在长推理链中造成 O(n2) 总分配。建议只发增量 delta 或使用 Arc,或 throttle 发送频率。

#5 — agent_session_history.rs:199 — convert_history_messages Phase 2 嵌套线性扫描 (O(M*N))

tool-call 合并使用嵌套线性查找 merge_target_pos,长对话中历史加载延迟随 session 长度平方增长。建议构建 HashMap<run_id, Vec<(position, ...)>> 索引实现 O(1) 查找。

#14 — agent_run_event_handler.rs:388 — ensure_reasoning_message 双重获取 async mutex

一次调用中获取 active_runs 锁两次,中间有 DB 写入,存在竞态窗口。建议重构为单次持锁或改变锁策略。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions