New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resize dict on del/pop #76804
Comments
We should investigate whether we want dicts to compact themselves on del/pop operations. Currently we have to rely on workarounds to have compactable dict.copy (see bpo-31179) etc. |
Note: It was recently discussed if "del dict[key]" should keep the insertion order. If I understood correctly: yes, the order must be preserved on deletion. https://mail.python.org/pipermail/python-dev/2017-November/150142.html |
For insert/pop loop, reduce table size aggressively on pop may cause So my opinion is:
|
I agree that an heuristic is needed to decide when a dict should be compacted.
In bpo-31179, I suggested to Yury to use 2/3 ratio... to avoid integer overflow :-) He first used 80%, but I dislike using the FPU in the dictobject.c. I'm not sure of the cost of switching from integers to floats, and more generally I hate rounding issues, so I prefer to use regular integers ;-) + (3) if 'mp' is non-compact ('del' operation does not resize dicts), By the way, if dict automatically compacts itself automatically, do we still need Yury's test "is the dict compact"? |
This issue is a matter of CPU vs memory tradeoff. It reminds me the PEP-393: str type doesn't make tradeoff anymore, CPython guarantee that str always use the most efficient storage (least memory) for characters. But here the tradeoff is different. A dict is mutable, whereas str is immutable ;-) |
This will cause significant performance regression for
This is bad too. This GROWTH_RATE is set in bpo-17563. |
"This will cause significant performance regression for Should we make sure that all dicts have at least MINSIZE entries? |
I don't think so. I think "allocate on first insert" is good idea for dict.clear() |
I think I understand bpo-17563, and I should fix GROWTH_RATE. Before compact-ordered dict, we can avoid resizing in But in compact-ordered dict, we can't do that. I think GROWTH_RATE should be ma_used*3 for now. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: