Repository navigation
Avoid quadratic copying in Table::getDisplayLines() - #202
Conversation
Merging every rendered row into the output with array_merge() copied the whole output array once per row, so rendering a table took quadratic time in the number of rows (about 4 s for 40,000 rows, and ~50 s for a `wp post list` of ~100k posts). Append the lines instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D26yjkN2BiqCXT6p6o1WqS
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthrough
ChangesTable rendering
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~8 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The supplied evidence identifies no unresolved behavior or merge-blocking risk in this localized rendering optimization. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Table::getDisplayLines()merged each rendered row into the output with$out = array_merge( $out, $row ). That copies the entire output array for every row, so rendering takes quadratic time in the number of rows.This shows up in WP-CLI's
--format=tablefor large result sets. On a test site with ~96,600 posts,wp post list --format=table --fields=ID,post_titletook 46 s, compared to ~7 s for--format=csvwith the same data. With this change it takes 7.4 s, and the output is byte-identical.The fix appends each rendered line to
$outinstead.Measurements
Rendering a two-column table with
getDisplayLines(), PHP 8.3:Testing
Added
test_display_lines_keep_row_order_with_many_rows. It renders 5,000 rows, every 100th of which spans two lines, and checks the line count, the order of the rows and the placement of the wrapped lines. The full PHPUnit suite passes. PHPCS reports no new violations in the touched files.Found while profiling WP-CLI for large lists (wp-cli/ideas#81, wp-cli/ideas#91).
🤖 Generated with Claude Code
https://claude.ai/code/session_01D26yjkN2BiqCXT6p6o1WqS
Generated by Claude Code
Summary by CodeRabbit