Skip to content

improve width() performance#181

Merged
jquast merged 8 commits into
masterfrom
jq/width-improvement
Jan 22, 2026
Merged

improve width() performance#181
jquast merged 8 commits into
masterfrom
jq/width-improvement

Conversation

@jquast

@jquast jquast commented Jan 22, 2026

Copy link
Copy Markdown
Owner

Performance improvement for most strings that are longer and contain escape sequences.

The "long loop" is only necessary to measure "cursor extent" for horizontal sequences and control character ('\b') -- we can use performance-optimized version if such sequences are detected as not found.

This does however have a negative effect of measuring VS-16 and ZWJ-related "glitch" sequences, which is no problem, wcwidth makes no guarantees of their measured length, but its worth writing negative test case to verify these conditions in future changes.

@codspeed-hq

codspeed-hq Bot commented Jan 22, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 58.63%

⚡ 7 improved benchmarks
✅ 31 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
test_width_udhr 193.3 ms 138.9 ms +39.18%
test_center_udhr_lines 2.5 ms 1.9 ms +35.61%
test_width_complex_ansi 83.6 µs 52.7 µs +58.63%
test_ljust_udhr_lines 2.4 ms 1.8 ms +37.83%
test_strip_sequences_simple 29.7 µs 26.5 µs +12.31%
test_wrap_japanese 5.9 ms 5.3 ms +10.89%
test_rjust_udhr_lines 2.4 ms 1.8 ms +37.73%

Comparing jq/width-improvement (85e8957) with master (7a398cb)

Open in CodSpeed

Yes, we have different results due to our "fast path" is not compatible
with "glitch emoji", and that's fine, at least until #134, #154, #133 is
done.
@codecov

codecov Bot commented Jan 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7a398cb) to head (85e8957).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #181   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           13        13           
  Lines          592       597    +5     
  Branches       142       145    +3     
=========================================
+ Hits           592       597    +5     

☔ 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 marked this pull request as ready for review January 22, 2026 20:45
@jquast jquast merged commit 9b58167 into master Jan 22, 2026
42 checks passed
@jquast jquast deleted the jq/width-improvement branch January 22, 2026 21:01
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.

1 participant