Declare istr with __slots__ = () in _multidict_py.py#1361
Conversation
Vizonex
left a comment
There was a problem hiding this comment.
If your going to use slots I would recommend trying to add __istr_identitiy__ to it. While I like your idea for speeding up pure python the tests reflect the issue.
AttributeError: 'istr' object attribute '__istr_identity__' is read-only
A Way you could slove this one is to try
__slots__ = ("__istr_identity__",)
|
Wait, but it's impossible to define a default value for a slot by setting it on the class, since that overwrites the slot. I changed the relevant logic a bit. |
for more information, see https://pre-commit.ci
Merging this PR will degrade performance by 21.09%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | test_iterate_multidict_keys[ci-py] |
245.1 µs | 346.6 µs | -29.29% |
| ❌ | test_iterate_multidict[ci-py] |
246.2 µs | 346.1 µs | -28.86% |
| ❌ | test_iterate_multidict_items[ci-py] |
264.4 µs | 364.3 µs | -27.42% |
| ❌ | test_keys_view_less_or_equal[ci-py] |
285.2 µs | 383.3 µs | -25.59% |
| ❌ | test_keys_view_less[ci-py] |
290.8 µs | 389.8 µs | -25.4% |
| ❌ | test_items_view_less[ci-py] |
335 µs | 437.1 µs | -23.35% |
| ❌ | test_items_view_less_or_equal[ci-py] |
332.6 µs | 433.6 µs | -23.28% |
| ❌ | test_multidict_popitem_str[ci-py] |
675.8 µs | 781.6 µs | -13.54% |
| ❌ | test_keys_view_sub[ci-py] |
1 ms | 1.2 ms | -11.92% |
| ❌ | test_keys_view_or[ci-py] |
1.1 ms | 1.3 ms | -9.83% |
| ❌ | test_items_view_or[ci-py] |
1.2 ms | 1.4 ms | -9.75% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing jonathandung:master (2de45be) with master (c63dfaf)1
Footnotes
for more information, see https://pre-commit.ci
|
@codspeedbot fix this regression |
|
I'm not familiar with this benchmarking framework, and I don't understand what it means by "different runtime environments detected". |
|
I have done all I can, and I think the regression was caused by CodSpeed running on a different virtual CPU. I'm not sure though. |
|
@webknjaz Any thoughts on this PR? |
What do these changes do?
Optimizes memory usage by preventing a dictionary to store attributes to be created on every
istrinstance.Are there changes in behavior for the user?
Users can no longer set attributes on the keys of the Python version of case-insensitive multidicts, mutable or otherwise.
Related issue number
Fixes #1360.
Checklist