Skip to content

Conversation

@jquast
Copy link
Owner

@jquast jquast commented Jan 26, 2026

From integration and study of downstream uses and needs, as documented in the primary new public API
function, porpagate_sgr(), there is a need to track, set, and reset SGR attributes at the
boundaries of returned lines when using wrap() and clip():

A related bug was discovered through extensive testing of "cafe" plus combining character,
that the combining characters were accidentally included outside of clip boundary, confused
with the zero-width nature of SGR codes

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 26, 2026

CodSpeed Performance Report

Merging this PR will degrade performance by 33.83%

Comparing jq/ansi-code-propagation (96727d6) with master (7de2e9b)

Summary

❌ 2 regressed benchmarks
✅ 48 untouched benchmarks
🆕 6 new benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 test_clip_with_ansi_no_propagate N/A 108.8 µs N/A
🆕 test_clip_complex_sgr N/A 251.8 µs N/A
🆕 test_wrap_complex_sgr N/A 481.2 µs N/A
test_clip_with_ansi 106 µs 160.2 µs -33.83%
test_wrap_with_ansi 301.8 µs 384.8 µs -21.56%
🆕 test_propagate_sgr_multiline N/A 143.9 µs N/A
🆕 test_wrap_with_ansi_no_propagate N/A 299.9 µs N/A
🆕 test_propagate_sgr_no_sequences N/A 32.3 µs N/A
@jquast
Copy link
Owner Author

jquast commented Jan 26, 2026

It is expected to be slower, however by "state tracking"

  • increase slightly number of sequences return by wrap() (extra terminator and start) for tradeoff of correctness -- ability to selective display of single line at a time
  • drastically reduce the total sequences returned by cut() to its minimum set by SGR tracking.

If this library is used to "build" text strings, those text strings now put less load on the terminal emulator, however it is certainly executed slower in python than in C, so it is a performance hit for correctness.

@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 93.18182% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.36%. Comparing base (b297eaf) to head (96727d6).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
wcwidth/sgr_state.py 92.48% 5 Missing and 8 partials ⚠️
wcwidth/wcwidth.py 95.12% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##            master     #194      +/-   ##
===========================================
- Coverage   100.00%   98.36%   -1.64%     
===========================================
  Files           13       14       +1     
  Lines          668      919     +251     
  Branches       164      234      +70     
===========================================
+ Hits           668      904     +236     
- Misses           0        6       +6     
- Partials         0        9       +9     

☔ View full report in Codecov by Sentry.
📢 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 merged commit 70dd591 into master Jan 26, 2026
38 checks passed
@jquast jquast deleted the jq/ansi-code-propagation branch January 26, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants