Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of cell_length #2061

Merged
merged 4 commits into from Mar 15, 2022
Merged

Improve performance of cell_length #2061

merged 4 commits into from Mar 15, 2022

Conversation

darrenburns
Copy link
Member

@darrenburns darrenburns commented Mar 14, 2022

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other - performance related change

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

5-6% performance improvement on python -m rich

Removes the use of the regex for detecting codepoints in ranges we know to be single characters. It was consistently slower regardless of where cache lookups happened.

I've also removed the bounds on key length on the cell_len cache, which resulted in another immediately noticeable improvement.

master:

❯ hyperfine "python -m rich"
Benchmark 1: python -m rich
  Time (mean ± σ):     144.6 ms ±   1.5 ms    [User: 135.5 ms, System: 8.2 ms]
  Range (min … max):   143.5 ms … 150.6 ms    20 runs

this branch:

❯ hyperfine "python -m rich"
Benchmark 1: python -m rich
  Time (mean ± σ):     138.8 ms ±   1.0 ms    [User: 129.6 ms, System: 8.1 ms]
  Range (min … max):   137.3 ms … 142.0 ms    21 runs

Combining this change and the other PR which adjusted regex and caching - cumulative time spend inside cell_len during python -m rich has dropped from 0.02047 to 0.0056. See image below (top is old, bottom is new).

image

@codecov-commenter
Copy link

codecov-commenter commented Mar 14, 2022

Codecov Report

Merging #2061 (c4cf06d) into master (91e0146) will increase coverage by 0.02%.
The diff coverage is 91.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2061      +/-   ##
==========================================
+ Coverage   99.49%   99.52%   +0.02%     
==========================================
  Files          73       72       -1     
  Lines        7361     7331      -30     
==========================================
- Hits         7324     7296      -28     
+ Misses         37       35       -2     
Flag Coverage Δ
unittests 99.52% <91.66%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
rich/align.py 100.00% <ø> (ø)
rich/layout.py 100.00% <ø> (ø)
rich/table.py 100.00% <ø> (ø)
rich/console.py 99.50% <80.00%> (-0.13%) ⬇️
rich/_win32_console.py 91.44% <100.00%> (+1.44%) ⬆️
rich/cells.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 51121fe...c4cf06d. Read the comment docs.

@darrenburns darrenburns marked this pull request as ready for review March 14, 2022 16:24
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.

None yet

3 participants