perf(console): avoid call to inspect.stack when possible#1253
perf(console): avoid call to inspect.stack when possible#1253willmcgugan merged 1 commit intoTextualize:masterfrom
Conversation
willmcgugan
left a comment
There was a problem hiding this comment.
Good optimization, but wouldn't want to risk breaking it on other Python implementations. There are a few now.
rich/console.py
Outdated
| ) | ||
| path = caller.filename.rpartition(os.sep)[-1] | ||
| line_no = caller.lineno | ||
| caller = inspect.currentframe() |
There was a problem hiding this comment.
According to the docs this function may return None if the interpreter isn't CPython. Not sure what supports it and what doesn't (Pypy maybe), but there would need to be a fallback that doesn't break.
2f50208 to
22b24d2
Compare
Codecov Report
@@ Coverage Diff @@
## master #1253 +/- ##
=======================================
Coverage 99.82% 99.82%
=======================================
Files 69 69
Lines 6410 6421 +11
=======================================
+ Hits 6399 6410 +11
Misses 11 11
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
4f835ce to
88ed70d
Compare
willmcgugan
left a comment
There was a problem hiding this comment.
Some missing lines from coverage. You can do make test to see coverage locally.
88ed70d to
5348ea7
Compare
5348ea7 to
32cae7f
Compare
32cae7f to
1b240d5
Compare
|
@willmcgugan should I make other changes (CHANGELOG/CONTRIBUTORS/...) or is this good to go? |
|
Definitely changelog. Contributors is up to you, if you would like a credit. PR looks good, thanks. Give me a little time to give it a proper review... |
This change improves the performance of the `Console.log` method by avoiding an expensive call to `stack()` and using `currentframe` instead. The same information is then available by navigating backward as many levels as required and peeking at the `code` object.
1b240d5 to
efa324a
Compare
Type of changes
Checklist
I've added tests for new code.Description
This change improves the performance of the
Console.logmethod by avoiding an expensive call tostack()and usingcurrentframeinstead. The same information is then available by navigating backward as many levels as required and peeking at thecodeobject.