#715: Parents probably not reclaimed due to too much caching
------------------------------------------------------------------------------------------------------------------------------------------+
Reporter: robertwb
| Owner:
somebody
Type: defect
| Status:
needs_info
Priority: major
| Milestone:
sage-4.8
Component: coercion
| Keywords:
weak cache coercion
Work_issues: Should we rename `TripleDictById` into `TripleDict`, or do we
want a "weak triple dictionary with comparison by equality"? | Upstream:
N/A
Reviewer:
| Author:
Simon King
Merged:
| Dependencies:
#9138, #11900
------------------------------------------------------------------------------------------------------------------------------------------+
Changes (by SimonKing):
* status: needs_work => needs_info
* work_issues: Rename `TripleDictById` into `TripleDict`. Improve timing
and update documentation => Should we
rename `TripleDictById` into
`TripleDict`, or do we want a "weak
triple dictionary with comparison by
equality"?
Comment:
I have posted a new patch version.
Recall that we want a dictionary whose keys are triples; we want to
compare all three key items by identity, and we want that there is only a
weak reference to the first two key items (the third my have a strong
reference).
The `TripleDictById` is now based on the following idea:
* There is one list that stores the memory addresses of the first two key
items and the third key item. In particular, I don't need to decref the
key items, since we only store their addresses.
* There is another list that stores the value corresponding to the key
triple, and stores weak references with a callback function to the first
two key items.
* When accessing the dictionary, the address of the first two key items
is compared with the stored address, and the third is compared by identity
with the stored data.
* Only when iterating over the `TripleDictById`, the weak references are
called (of course: iteritems is supposed to return the keys, not just the
address of the keys).
* There are two reasons for storing the weak references (and not only the
addresses): The callback function of the weak references removes unused
entries of the dictionary, and we also need it for iteration over the
dictionary.
__Status of the patch__
* The "raw" speed seems to be almost as good as in the unpatched version,
the speed of doctests seems to be OK, and I don't observe segfaults.
* The memleak is fixed.
* The documentation of sage/structure/coerce_dict.pyx needs more
polishing, and last but not least I did not run the doctests yet.
The patch still contains both `TripleDict` (which compares weak keys by
equality) and `TripleDictById` (which compares keys by identity, similar
to what `TripleDict` does in unpatched Sage, but using weak references).
What do you think: Should comparison by equality be provided in the patch?
Contra:
We don't use it in the rest of Sage, so, why should we add it?
Pro:
A "triple dict by comparison" is slower than a usual (strong) dictionary,
but on the other hand `weakref.WeakKeyDictionary` does not work if the
keys are tuples - hence, "triple dict by comparison" adds a new feature.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/715#comment:125>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.