cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Multiple files use `tuple()`, `list()` and `dict()`

Open Ombucha opened this issue 2 years ago • 4 comments

Bug report

Multiple files use tuple(), list() and dict(), which can slow down performance.

Ombucha avatar Oct 16 '22 06:10 Ombucha

You also try to change Exception or Exception to just Exception in test_bpo_42057, even though BPO 42057 makes it look like the duplication is intentional and essential. Do you understand why it is the way it is? And can you explain why it's not needed? You didn't even mention that change. Looks like Chesterton's fence (good long post).

How much do those tuple() etc calls slow down performance? And can you explain why they are the way they are, and why they don't need to be?

pochmann avatar Oct 16 '22 08:10 pochmann

You also try to change Exception or Exception to just Exception in test_bpo_42057, even though BPO 42057 makes it look like the duplication is intentional and essential.

I have reverted this change.

How much do those tuple() etc calls slow down performance? And can you explain why they are the way they are, and why they don't need to be?

It can be inferred from this Stack Overflow answer that tuple() is much slower that just ().

Ombucha avatar Oct 16 '22 10:10 Ombucha

I know it's slower. And that answer shows differences of 140 nanoseconds. Is that even measurable in the cases you've changed?

pochmann avatar Oct 16 '22 11:10 pochmann

I am not sure about that.

Ombucha avatar Oct 16 '22 11:10 Ombucha

Per the PR discussion, marking as closed.

Also a few other comments might be helpful when thinking about this. Generally, we try to avoid sweeping through many modules at once because it risks destabilizing code and it makes it harder to backport actual bugfixes. Also, it is not wrong to write dict(), list(), or tuple(). Sometimes that reflects the authors way of thinking about the problem and lets them highlight or call out the type for emphasis. Most of the edits in the PR were aimed at tests or tools where we really don't care about micro-performance.

rhettinger avatar Oct 16 '22 18:10 rhettinger