Skip to content

Various performance gains, shortcuts and bitsets - #303

Merged
jquast merged 8 commits into
masterfrom
jq/performance-experiments
Oct 24, 2026
Merged

jquast merged 8 commits into
masterfrom
jq/performance-experiments

Conversation

@jquast

@jquast jquast commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

I tested bitsets long ago in python (only) with similar ~1-1.3x results and decided the performance improvement did not improve the readability, and again recently in September and declined again for libwcwidth,

Improvement was only up to 1.2x with WIDE and other "hot path" tables, with more tables for diminishing returns, code is too complex

I am now willing to make the tradeoff for the marginal performance win.

Which tables are selected for bitset was chosen by our benchmarks, bisearch is still used for some tables where it performs better. In libwcwidth and python wcwidth, all previously exported codepoint range tables remain, even though they are now sometimes unused in libwcwidth/python+build_ext.

The GraphemeBreakTest.txt is missing a test for this bug, so we create
our own using TDD.

This bug was found by static analysis, it would be uncommon in practical
use, the highest level functions already split or replace errant control
characters (newline, tab), escape sequences are iterated over, and even
the low-level graphemes functions used by editors also avoid likely
control characters.
@codspeed

codspeed Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 61.53%

1 warning

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

⚡ 59 improved benchmarks
✅ 78 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_iter_graphemes_reverse_cjk 580.3 µs 51.4 µs ×11
⚡ test_iter_graphemes_reverse_long 979.2 µs 130.5 µs ×7.5
⚡ test_grapheme_boundary_before_long_end 154.6 µs 26.3 µs ×5.9
⚡ test_grapheme_boundary_before_long_mid 154.5 µs 26.3 µs ×5.9
⚡ test_grapheme_boundary_before_cjk 122.8 µs 24.9 µs ×4.9
⚡ test_grapheme_boundary_before_short 116.7 µs 24.5 µs ×4.8
⚡ test_iter_graphemes_reverse_short 190.8 µs 49.3 µs ×3.9
⚡ test_iter_graphemes_reverse_latin1 182 µs 49.6 µs ×3.7
⚡ test_iter_graphemes_start_long 146.5 µs 44.3 µs ×3.3
⚡ test_clip_cursor_cr_control_codes_ignore 1,329.8 µs 576.1 µs ×2.3
⚡ test_clip_cursor_cr_overwrite 6.2 ms 3 ms ×2
⚡ test_clip_cursor_cr_to_end 6.3 ms 3.1 ms ×2
⚡ test_iter_graphemes_reverse_ascii 96.8 µs 48.3 µs ×2
⚡ test_clip_cursor_csi_backward 4.5 ms 2.3 ms +96.48%
⚡ test_clip_long_cjk_control_codes_ignore 1,068.7 µs 604.3 µs +76.87%
⚡ test_grapheme_boundary_before_latin1 40.1 µs 23 µs +74.22%
⚡ test_clip_cjk_paragraph_overtyping 34.2 ms 21.8 ms +56.77%
⚡ test_clip_dense_ansi_control_codes_ignore 1,173.3 µs 777.8 µs +50.85%
⚡ test_clip_long_cjk_overtype 1,356.6 µs 904.7 µs +49.95%
⚡ test_iter_graphemes_cjk 149.6 µs 104.5 µs +43.18%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

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


Comparing jq/performance-experiments (a7a4e2a) with master (4bb1017)

Open in CodSpeed

@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.09%. Comparing base (4bb1017) to head (a7a4e2a).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #303      +/-   ##
==========================================
+ Coverage   87.84%   88.09%   +0.25%     
==========================================
  Files          41       41              
  Lines        5625     5654      +29     
  Branches     1510     1520      +10     
==========================================
+ Hits         4941     4981      +40     
  Misses        319      319              
+ Partials      365      354      -11     

☔ 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.

Comment thread tests/test_textwrap.py Fixed
@jquast jquast changed the title Improve width and grapheme iteration mostly using bitsets Various performance gains, shortcuts and bitsets Oct 23, 2026
@jquast
jquast merged commit ffb4a74 into master Oct 24, 2026
38 checks passed
@jquast
jquast deleted the jq/performance-experiments branch October 24, 2026 13:54
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