Optimize filter-map chaining into single-pass operations#1302
Optimize filter-map chaining into single-pass operations#1302ParkerMichaelsen wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThis PR replaces multiple ChangesCollection pipeline refactor
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/components/agents/AgentsList.tsx (1)
245-247: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winAvoid
flatMap(...).map(...)in these render paths.Both changes still traverse the result again and allocate intermediate arrays, so they do not provide the intended single-pass optimization and may be slower than the original
filter(...).map(...). Return the rendered nodes directly fromflatMapor use a reducer that appends the JSX nodes.Also applies to: 275-277
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/components/agents/AgentsList.tsx` around lines 245 - 247, Update the render paths around the AGENT_SOURCE_GROUPS iterations to eliminate the chained flatMap(...).map(...) traversal and intermediate arrays. Have flatMap directly return the rendered JSX nodes for each non-built-in group, returning an empty array for excluded groups, and apply the same single-pass approach to the second occurrence near the other referenced path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/components/agents/AgentsList.tsx`:
- Around line 245-247: Update the render paths around the AGENT_SOURCE_GROUPS
iterations to eliminate the chained flatMap(...).map(...) traversal and
intermediate arrays. Have flatMap directly return the rendered JSX nodes for
each non-built-in group, returning an empty array for excluded groups, and apply
the same single-pass approach to the second occurrence near the other referenced
path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b71c2ba1-9837-4a23-a11d-e1545a7a8521
📒 Files selected for processing (19)
packages/@ant/computer-use-mcp/src/toolCalls.tspackages/builtin-tools/src/tools/TaskListTool/TaskListTool.tssrc/commands/plugin/ManagePlugins.tsxsrc/components/Spinner.tsxsrc/components/TaskListV2.tsxsrc/components/agents/AgentsList.tsxsrc/components/memory/MemoryFileSelector.tsxsrc/components/messages/CollapsedReadSearchContent.tsxsrc/components/permissions/rules/PermissionRuleList.tsxsrc/hooks/useTaskListWatcher.tssrc/services/autoDream/consolidationLock.tssrc/skills/bundled/ultracode.tssrc/utils/groupToolUses.tssrc/utils/messages.tssrc/utils/pipeRegistry.tssrc/utils/plugins/dependencyResolver.tssrc/utils/plugins/pluginDirectories.tssrc/utils/swarm/inProcessRunner.tssrc/utils/tasks.ts
Summary
Optimized 18 filter-map chaining inefficiencies across 19 files by combining them into single-pass
reduce()operations. This eliminates duplicate array passes and reduces memory allocations while maintaining the same functionality.Changes
High-Priority (Render Paths & Hot Loops)
src/components/TaskListV2.tsx (3 chains)
src/components/Spinner.tsx (1 chain)
src/utils/tasks.ts (2 chains)
src/hooks/useTaskListWatcher.ts (1 chain)
src/utils/swarm/inProcessRunner.ts (1 chain)
Medium-Priority (Hot Utilities)
src/utils/groupToolUses.ts (1 chain)
src/utils/messages.ts (1 chain)
src/utils/plugins/dependencyResolver.ts (2 chains)
src/services/autoDream/consolidationLock.ts (1 chain)
src/utils/plugins/pluginDirectories.ts (1 chain)
Lower-Priority (UI Components & Tools)
src/utils/pipeRegistry.ts (1 chain)
packages/@ant/computer-use-mcp/src/toolCalls.ts (1 chain)
src/components/permissions/rules/PermissionRuleList.tsx (1 chain)
src/components/messages/CollapsedReadSearchContent.tsx (1 chain)
src/components/memory/MemoryFileSelector.tsx (1 chain)
src/components/agents/AgentsList.tsx (2 chains)
src/commands/plugin/ManagePlugins.tsx (1 chain)
src/skills/bundled/ultracode.ts (1 chain)
Performance Impact
✅ Eliminated duplicate array passes: Each filter-map previously iterated the collection twice (filter pass + map pass), now only one pass with reduce
✅ Reduced memory allocations: Fewer intermediate arrays created and garbage collected
✅ Clearer intent: Reduce pattern makes the single-pass nature explicit
Files Modified
Testing Notes
All refactored chains maintain 100% functional equivalence with the original code. The transformations use:
reduce()withifconditions for filteringflatMap()with conditional returns for cleaner structureVerified no filter-map chains remain in the codebase after refactoring.
Summary by CodeRabbit