Skip to content

Improve clip() and truncate() performance - #434

Merged
jquast merged 7 commits into
masterfrom
pr-427
Nov 14, 2026
Merged

jquast merged 7 commits into
masterfrom
pr-427

Conversation

@jquast

@jquast jquast commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

This follows up #427, simplifying it a bit, it's something I missed in wcwidth integration #420.

It's also not necessarily a "bugfix" but rather an "improvement" in performance. The call to padd() is removed, which was originally done as a hack to replace tabs or "cursor right" \x1b[10C to spaces, ' '*10, and only so that it would be easily measured or truncated

Closes #427.

@codspeed

codspeed Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by ×7.1

1 warning

⚠️ 3 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 3 improved benchmarks
✅ 28 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_truncate_ansi 38,177.1 µs 165.7 µs ×230
⚡ test_truncate_ascii 161.3 µs 117.9 µs +36.76%
⚡ test_truncate_cjk 175.2 µs 154 µs +13.81%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing pr-427 (99cf83c) with master (7fbbd90)

Open in CodSpeed

@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.76%. Comparing base (7fbbd90) to head (99cf83c).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #434   +/-   ##
=======================================
  Coverage   97.76%   97.76%           
=======================================
  Files          13       13           
  Lines        4118     4118           
  Branches      697      697           
=======================================
  Hits         4026     4026           
  Misses         70       70           
  Partials       22       22           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jquast
jquast marked this pull request as ready for review November 14, 2026 15:15
@jquast jquast changed the title Improve clip() and truncate() for cursor movement Improve clip() and truncate() performance Nov 14, 2026
@jquast
jquast merged commit 663e867 into master Nov 14, 2026
14 of 16 checks passed
@jquast
jquast deleted the pr-427 branch November 14, 2026 15:19
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.

2 participants