bloomberg / memray

Memray is a memory profiler for Python
https://bloomberg.github.io/memray/
Apache License 2.0
13.17k stars 392 forks source link

Make minor performance improvements using ruff rules C4 and PERF #500

Closed cclauss closed 10 months ago

cclauss commented 10 months ago

Issue number of the reported bug or feature request: #

Describe your changes A clear and concise description of the changes you have made. Make minor performance improvements using ruff rules C4 and PERF.

9   PERF102 [*] When using only the keys of a dict use the `keys()` method
9   PERF401 [ ] Use a list comprehension to create a transformed list
4   C401    [*] Unnecessary generator (rewrite as a `set` comprehension)
4   C402    [*] Unnecessary generator (rewrite as a `dict` comprehension)
4   C408    [*] Unnecessary `dict` call (rewrite as a literal)
3   C405    [*] Unnecessary `list` literal (rewrite as a `set` literal)
1   C416    [*] Unnecessary `dict` comprehension (rewrite using `dict()`)

Testing performed Describe the testing you have performed to ensure that the bug has been addressed, or that the new feature works as planned. % ruff --select=C4,PERF .

Additional context Add any other context about your contribution here.

codecov-commenter commented 10 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (c4b35f3) 92.32% compared to head (b556a9a) 92.22%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #500 +/- ## ========================================== - Coverage 92.32% 92.22% -0.10% ========================================== Files 91 91 Lines 11033 11033 Branches 1524 1524 ========================================== - Hits 10186 10175 -11 - Misses 842 853 +11 Partials 5 5 ``` | [Flag](https://app.codecov.io/gh/bloomberg/memray/pull/500/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bloomberg) | Coverage Δ | | |---|---|---| | [cpp](https://app.codecov.io/gh/bloomberg/memray/pull/500/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bloomberg) | `85.66% <ø> (-0.31%)` | :arrow_down: | | [python_and_cython](https://app.codecov.io/gh/bloomberg/memray/pull/500/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bloomberg) | `95.48% <100.00%> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bloomberg#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

godlygeek commented 10 months ago

Everything under benchmarks/ is vendored code that we don't want to modify - please revert the changes to those files. We should instead configure ruff to not lint that directory. Also, we should configure ruff to always apply the C4 and PERF rules if we're going to make these changes, since otherwise there's nothing stopping us from regressing on them.

All the changes to our source code and tests seem fine, though. I think some of the dictionary literals are a bit less readable than the calls to the dict() constructor they're replacing, but the difference is probably not enough to worry about.