# 终端模拟性能优化心得(2025年10月) ## 问题背景 用户反馈化工订单班终端输出速度过快,缺乏真实感。经分析发现多个订单班存在同样问题。 ## 根本原因 - 缺少progress类型输出(带有stutters的进度条) - 过度依赖output类型(延迟仅30-100ms) - 缺少system类型输出作为间隔 ## 延迟机制分析 ```typescript // WorkflowPageV4.tsx中的延迟配置 const delay = output.type === 'system' ? getRandomDelay(100, 300) : output.type === 'progress' ? 0 : // progress有自己的时间控制 getRandomDelay(30, 100); // Progress类型的特殊处理 if (stutters.includes(progress)) { await new Promise(resolve => setTimeout(resolve, getRandomDelay(1000, 3000))); } ``` ## 优化方案 1. **为每个Agent添加2-3个进度条** - 使用stutters数组制造暂停效果:`[23, 56, 78]`或`[34, 67, 89]` - 部分进度条可添加duration参数:`duration: 2000` 2. **添加system类型输出** - Agent初始化信息:`>>> Agent-1: 项目经理初始化...` - 技术细节:`CUDA环境检测: Available`、`GPU内存分配: 8GB` - 空行分隔:`{ type: 'system', content: '' }` 3. **优化后的统计** - environmental.ts: 添加15个进度条 - transportation.ts: 添加20个进度条 - developer.ts: 添加18个进度条 - finance.ts: 添加14个进度条 - chemical.ts: 添加7个进度条(之前已优化) ## 最佳实践模板 ```typescript { agent: () => agents[0], outputs: [ { type: 'info', content: '🔧 Agent名称开始工作...' }, { type: 'system', content: '' }, { type: 'progress', content: '任务1', target: 100, stutters: [23, 56, 78] }, { type: 'progress', content: '任务2', target: 100, stutters: [45, 89] }, { type: 'system', content: '' }, // ... 具体输出内容 ] } ``` ## 效果提升 - 单个Agent输出时间从2-3秒提升至5-8秒 - 整体终端模拟时间从15-20秒提升至30-45秒 - 用户体验更真实,避免输出过快的问题 ## 注意事项 - 不要过度添加进度条,每个Agent 2-3个即可 - stutters数组的值应该多样化,避免重复 - 适当使用system类型输出作为视觉间隔 - 保持代码简洁,避免臃肿