Skip to content

Addresses #5627. Skip clean runs during output flush - #5633

Merged
YourRobotOverlord merged 3 commits into
tui-cs:developfrom
YourRobotOverlord:fix/skip-clean-runs
Aug 22, 2026
Merged

YourRobotOverlord merged 3 commits into
tui-cs:developfrom
YourRobotOverlord:fix/skip-clean-runs

Conversation

@YourRobotOverlord

@YourRobotOverlord YourRobotOverlord commented Aug 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Optimize OutputBase.Write so sparse dirty rows skip clean gaps instead of emitting one cursor-position operation per clean cell.

Changes

  • Accumulate and flush consecutive dirty cells as output runs
  • Position the cursor once at the beginning of each dirty run
  • Preserve hyperlink, raster, wide-grapheme, legacy-console, and dirty-row behavior
  • Add 270x72 full-frame and sparse-border BenchmarkDotNet coverage
  • Add a Windows ConPTY benchmark command and regression tests

Benchmarks

Case Before After Result
Sparse BenchmarkDotNet mean 2.741 ms 0.704 ms 3.89x faster
Sparse allocation 3.83 MiB 300.53 KiB 92.3% lower
Sparse cursor calls 19,440 144 135x fewer
ConPTY median 347.196 ms 5.713 ms 60.8x faster
ConPTY p95 353.920 ms 6.070 ms 58.3x faster

Full-frame BenchmarkDotNet performance remained effectively flat. Content writes remain unchanged at 144 for the sparse frame.

Testing

  • Debug build: 0 warnings, 0 errors
  • OutputBaseTests: 73 passed
  • Parallelizable unit tests: 17,575 passed, 17 skipped
  • Non-parallelizable unit tests: 72 passed, 2 skipped
  • Integration tests: 437 passed
  • ConPTY captures used tuirec v0.9.1 at 270x72

To pull down this PR locally:

git remote add yor https://github.com/YourRobotOverlord/Terminal.Gui.git
git fetch yor fix/skip-clean-runs
git checkout --track yor/fix/skip-clean-runs

Avoid one cursor-position sequence per clean cell in sparse dirty rows.

Refs tui-cs#5627
@YourRobotOverlord
YourRobotOverlord requested a review from tig as a code owner August 22, 2026 18:56
@YourRobotOverlord
YourRobotOverlord marked this pull request as draft August 22, 2026 19:00
@YourRobotOverlord
YourRobotOverlord marked this pull request as ready for review August 22, 2026 19:07
@YourRobotOverlord

Copy link
Copy Markdown
Collaborator Author

Before:
before
After:
after

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves OutputBase.Write performance for sparse frames by skipping clean gaps within dirty rows, reducing cursor-position operations and console writes while preserving existing hyperlink/raster/wide-grapheme behaviors. It also adds benchmarks and regression tests to validate the new flush strategy and quantify performance changes.

Changes:

  • Update OutputBase.Write to flush consecutive dirty-cell runs and skip clean gaps without per-cell cursor moves.
  • Add unit tests validating cursor-move and dirty-flag behavior for sparse and multi-run output.
  • Add benchmark coverage (BenchmarkDotNet + ConPTY mode) and documentation for measuring output flush performance.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Terminal.Gui/Drivers/Output/OutputBase.cs Implements skipping clean gaps within dirty rows and run-based cursor positioning/flush logic.
Tests/UnitTestsParallelizable/Drivers/Output/OutputBaseTests.cs Adds regression tests for sparse-border and multi-run dirty output; extends test output instrumentation.
Tests/Benchmarks/ConsoleDrivers/OutputBuffer/OutputWriteBenchmark.cs Introduces benchmarks for full-frame vs sparse-frame flush, plus a Windows ConPTY timing mode.
Tests/Benchmarks/Program.cs Adds a CLI entry point for running the ConPTY output benchmark (output-conpty).
Tests/Benchmarks/README.md Documents how to run the new output flush benchmarks, including ConPTY instructions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Terminal.Gui/Drivers/Output/OutputBase.cs
YourRobotOverlord and others added 2 commits August 22, 2026 14:24
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
wth, copilot

@tig tig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done. Thank you!

@YourRobotOverlord
YourRobotOverlord merged commit 9ab60bc into tui-cs:develop Aug 22, 2026
14 checks passed
@YourRobotOverlord
YourRobotOverlord deleted the fix/skip-clean-runs branch August 22, 2026 21:59
liuqihonggit added a commit to liuqihonggit/Terminal.Gui that referenced this pull request Aug 26, 2026
3-way merge: #5633循环重构 + Utf8Buffer替换,解决OutputBaseTests失败
tig pushed a commit that referenced this pull request Sep 14, 2026
Utf8Buffer replaces StringBuilder to eliminate char[] to UTF8 conversion in output hot path.

AnsiOutput batch mode merges pendingCursorMoves + output.

BuildAnsiForRegionSkippingRasterCoveredBlanks uses Utf8Buffer.

Note: needs rebase after upstream #5633 merges.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OutputBase.Write issues one cursor-move console write per clean cell, making sparse frames far more expensive than full ones

3 participants