Skip to content

Cache system lookups to save invocation time#107

Merged
hugovk merged 1 commit intotermcolor:mainfrom
miketheman:miketheman/cache-lookups
Apr 14, 2025
Merged

Cache system lookups to save invocation time#107
hugovk merged 1 commit intotermcolor:mainfrom
miketheman:miketheman/cache-lookups

Conversation

@miketheman
Copy link
Contributor

Caching the output of the lookups performed drops time from 3-5 milliseconds to hundreds of nanoseconds, as calls to os.environ and other system indicators are unlikely to change within the course of a running process.

Using the cache decorator allows for passing in no_color/force_color params to change the desired behavior, while allowing the text and colors to be different without increasing the cache size.

Resolves #48

Caching the output of the lookups performed drops time from 3-5
milliseconds to hundreds of nanoseconds, as calls to `os.environ` and
other system indicators are unlikely to change within the course of a
running process.

Using the `cache` decorator allows for passing in `no_color/force_color`
params to change the desired behavior, while allowing the text and
colors to be different without increasing the cache size.

Resolves termcolor#48

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
@codecov
Copy link

codecov bot commented Apr 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.13%. Comparing base (92af748) to head (e516dd5).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #107      +/-   ##
==========================================
+ Coverage   97.79%   98.13%   +0.34%     
==========================================
  Files           3        3              
  Lines         136      161      +25     
==========================================
+ Hits          133      158      +25     
  Misses          3        3              
Flag Coverage Δ
macos-latest 98.13% <100.00%> (+0.34%) ⬆️
ubuntu-latest 98.13% <100.00%> (+0.34%) ⬆️
windows-latest 98.13% <100.00%> (+0.34%) ⬆️

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

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

@hugovk hugovk added the changelog: Added For new features label Apr 14, 2025
@hugovk hugovk merged commit 60815d2 into termcolor:main Apr 14, 2025
31 of 32 checks passed
@hugovk
Copy link
Member

hugovk commented Apr 14, 2025

Thank you!

@miketheman miketheman deleted the miketheman/cache-lookups branch April 14, 2025 15:17
bwoodsend added a commit to bwoodsend/polycotylus that referenced this pull request May 20, 2025
As of termcolor/termcolor#107, mid-process changes to FORCE_COLOR/NO_COLOR
are no longer respected without poking into the guts to clear a private LRU
cache. Hopefully we'll get a better way of doing this
(termcolor/termcolor#113).
bwoodsend added a commit to bwoodsend/polycotylus that referenced this pull request May 21, 2025
As of termcolor/termcolor#107, mid-process changes to
FORCE_COLOR/NO_COLOR are no longer respected without poking into the
guts to clear a private LRU cache. A public reset is in progress
(termcolor/termcolor#114).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: Added For new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terminal check not cached

2 participants