Cache system lookups to save invocation time#107
Merged
hugovk merged 1 commit intotermcolor:mainfrom Apr 14, 2025
Merged
Conversation
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 ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
Thank you! |
This was referenced May 1, 2025
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Caching the output of the lookups performed drops time from 3-5 milliseconds to hundreds of nanoseconds, as calls to
os.environand other system indicators are unlikely to change within the course of a running process.Using the
cachedecorator allows for passing inno_color/force_colorparams to change the desired behavior, while allowing the text and colors to be different without increasing the cache size.Resolves #48