Repository navigation
Closed
Labels
Description
| BPO | 13903 |
|---|---|
| Nosy | @loewis, @rhettinger, @terryjreedy, @gpshead, @jcea, @pitrou, @vstinner, @pjenvey, @benjaminp, @markshannon, @JimJJewett |
| Files |
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:
assignee = None
closed_at = <Date 2012-05-02.17:09:34.992>
created_at = <Date 2012-01-29.14:26:46.386>
labels = ['interpreter-core', 'performance']
title = 'New shared-keys dictionary implementation'
updated_at = <Date 2012-05-12.21:52:57.593>
user = 'https://github.com/markshannon'bugs.python.org fields:
activity = <Date 2012-05-12.21:52:57.593>
actor = 'python-dev'
assignee = 'none'
closed = True
closed_date = <Date 2012-05-02.17:09:34.992>
closer = 'benjamin.peterson'
components = ['Interpreter Core']
creation = <Date 2012-01-29.14:26:46.386>
creator = 'Mark.Shannon'
dependencies = []
files = ['24510', '24670', '24766', '25096', '25313', '25318', '25339', '25340', '25381', '25385', '25422']
hgrepos = ['112']
issue_num = 13903
keywords = ['patch']
message_count = 43.0
messages = ['152229', '152253', '152293', '152345', '152351', '152366', '152373', '152380', '152419', '152863', '152885', '154637', '154645', '155246', '155248', '156096', '157365', '157466', '157477', '157482', '157500', '157649', '158051', '158192', '158723', '159018', '159028', '159031', '159032', '159049', '159055', '159139', '159143', '159161', '159172', '159188', '159478', '159484', '159485', '159489', '159683', '159698', '160496']
nosy_count = 14.0
nosy_names = ['loewis', 'rhettinger', 'terry.reedy', 'gregory.p.smith', 'jcea', 'pitrou', 'vstinner', 'pjenvey', 'benjamin.peterson', 'Yury.Selivanov', 'Mark.Shannon', 'python-dev', 'jcon', 'Jim.Jewett']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'performance'
url = 'https://bugs.python.org/issue13903'
versions = ['Python 3.3']
Activity
markshannon commentedon Jan 29, 2012
The proposed dictionary implementation allows sharing of keys & hashes between dictionaries. This leads to substantial memory savings for object-oriented programs. For non-OO programs the impact is negligible.
terryjreedy commentedon Jan 29, 2012
In the initial comment, 'Dummy' to 'Deleted' here but only here:
+ Holds an active (key, value) pair. Active can transition to Deleted
Im Lib/test/test_pprint.py
def test_set_reprs(self): ...
# Consequently, this test is fragile and ...
+ # XXX So why include this "test" in the first place?
Raymond, I believe you added this 44927 and revised for 3.x in 45067.
I imagine it will also be a problem with randomized hashes. Should it be removed or somehow revised?
vstinner commentedon Jan 30, 2012
I see two unrelated parts in your patch:
You may open a new issue for the second part, except if I am wrong and you need to change constants for the first part?
(I don't understand why you changed constants and how you chose new values.)
rhettinger commentedon Jan 30, 2012
This would likely require a PEP before having a chance of being considered for inclusion.
markshannon commentedon Jan 30, 2012
Does this really need a PEP?
There is no new language feature and no change to any API.
It is just saving some memory.
The only possible issue is changing dict repr() ordering,
but bpo-13703 will do that anyway.
rhettinger commentedon Jan 31, 2012
Changing dictionaries is a big deal. You're changing many pieces at once (not a good idea) including changing tunable parameters that are well-studied (I spent a month testing whether 5/8 was better idea that 2/3 for resizing or when the ideal small dict size was 4, 8, or 16). You're changing the meaning of the fields in dictobject.h which will likely break any code that relied on those.
The ideas may be good ones but they warrant a good deal of thought. Dicts weren't just slapped together -- the current code is the product to two decades of tweaking by engineers who devoted significant time to the task. It would be easy to unknowingly undo some of their work.
markshannon commentedon Jan 31, 2012
Raymond Hettinger wrote:
OK.
I'll write a PEP.
By the way, I'm trying not changing the tunable parameters for the
unshared-keys case, just the shared-keys case. Of course, they do
interact with each other.
pitrou commentedon Jan 31, 2012
As Victor I think the tunables could be changed separately, unless they truely get in the way of the shared-keys optimization.
By the way, there will need a "protection" for the case where instances are used as bags of key/value pairs (dict-alikes with attribute access). Perhaps bound the size of the keys array to 100 entries and then switch into unshared mode.
gpshead commentedon Feb 1, 2012
FYI - I strongly support this type of work to reduce memory use of the Python interpreter! :)
Also, yes, constant changing should be separate from this change but are worth occasionally re-measuring and justifying as common computer architectures have changed since the original decisions were made.
pitrou commentedon Feb 8, 2012
Looking at your latest patch, I worry about "any deletion
+(including pop & popitem) causes a split table to become a combined table". Why wouldn't you use a dummy pointer (such as ((PyObject *) 1)) to signal deleted slots?
markshannon commentedon Feb 8, 2012
Antoine Pitrou wrote:
In fact here is no need for a dummy pointer.
When deleting from a split-table, the value can just be set to NULL,
the resulting key-NULL pair is legal in a split-table.
Your suggestion doesn't make the code any more complex, so I've included it.
In practice, it will very rare that a deletion occurs in a split table
(since they are only used for attribute dictionaries).
jimjjewett commentedon Feb 29, 2012
As of Feb 28, 2012, the PEP mentions an additional optimization of storing the values in an array indexed by (effectively) key insertion order, rather than key position. ("Alternative Implementation")
It states that this would reduce memory usage for the values array by 1/3. 1/3 is a worst-case measurement; average is 1/2. (At savings of less than 1/3, the keys would resize, to initial savings of 2/3. And yes, that means in practice, the average savings would be greater than half, because the frequency of dicts of size N decreases with N.)
It states that the keys table would need an additional "values_size" field, but in the absence of dummies, this is just ma_used.
Note that this would also simplify resizing, as the values arrays would not have to be re-ordered, and would not have to be modified at all unless/until that particular instance received a value for a position beyond its current size.
21 remaining items
python-dev commentedon Apr 23, 2012
New changeset 34b6998efd2c by Benjamin Peterson in branch 'default':
fix instance dicts with str subclasses (bpo-13903)
http://hg.python.org/cpython/rev/34b6998efd2c
markshannon commentedon Apr 24, 2012
Failing to maintain GC tracking in setdefault and copy (for split-tables)
Patch attached
python-dev commentedon Apr 24, 2012
New changeset 507a6703d6a3 by Benjamin Peterson in branch 'default':
fix dict gc tracking (bpo-13903)
http://hg.python.org/cpython/rev/507a6703d6a3
markshannon commentedon Apr 24, 2012
Failed to differentiate between failure and error in make_split_table().
Patch attached
python-dev commentedon Apr 24, 2012
New changeset b044e0568be2 by Martin v. Loewis in branch 'default':
Account for shared keys in type's __sizeof__ (bpo-13903).
http://hg.python.org/cpython/rev/b044e0568be2
python-dev commentedon Apr 24, 2012
New changeset 5d5b72a71898 by Benjamin Peterson in branch 'default':
distiguish between refusing to creating shared keys and error (bpo-13903)
http://hg.python.org/cpython/rev/5d5b72a71898
markshannon commentedon Apr 27, 2012
Decref cached-keys when type is deallocated.
Patch attached.
python-dev commentedon Apr 27, 2012
New changeset a3beae842f13 by Benjamin Peterson in branch 'default':
decref cached keys on type deallocation (bpo-13903)
http://hg.python.org/cpython/rev/a3beae842f13
pitrou commentedon Apr 27, 2012
Is there any way to detect / avoid leaks on this separate refcounting
scheme?
pitrou commentedon Apr 27, 2012
This patch integrates the dictkeys' refcounting into the refcount checking framework. Seems to work ok, but it would be better if someone more acquainted with the code could confirm it.
markshannon commentedon Apr 30, 2012
Change insertdict to follow normal (non-stealing) ref-counting behaviour which fixes possible leakage.
Patch attached.
python-dev commentedon Apr 30, 2012
New changeset c5fd332e5857 by Benjamin Peterson in branch 'default':
change insertdict to not steal references (bpo-13903)
http://hg.python.org/cpython/rev/c5fd332e5857
python-dev commentedon May 12, 2012
New changeset 10e8b97d0fd7 by Antoine Pitrou in branch 'default':
Make the reference counting of dictkeys objects participate in refleak hunting
http://hg.python.org/cpython/rev/10e8b97d0fd7