#13394: Write a WeakValueDictionary with safer key removal
-------------------------------------+-------------------------------------
Reporter: nbruin | Owner: rlm
Type: enhancement | Status: positive_review
Priority: major | Milestone: sage-5.13
Component: memleak | Resolution:
Keywords: | Merged in:
Authors: Simon King, Nils | Reviewers: Nils Bruin, Simon
Bruin | King
Report Upstream: None of the above | Work issues:
- read trac for reasoning. | Commit:
Branch: | 1a12ce6982bbe1f050e4ae627972023d5ddfa5ef
u/SimonKing/ticket/13394 | Stopgaps:
Dependencies: |
-------------------------------------+-------------------------------------
Changes (by nbruin):
* status: needs_review => positive_review
* reviewer: Simon King => Nils Bruin, Simon King
Old description:
> On ticket #12313 we found that the use of `WeakValueDictionaries` as
> caches can cause `removal` callbacks in rather harsh environments. Normal
> `WeakValueDictionaries` remove keys with dead values by looking up the
> key. This involves Python equality testing on the key, which can cause
> any kind of operation in Sage. We need a dictionary where we can delete
> entries without key comparisons. See below for possible strategies.
New description:
On ticket #12313 we found that the use of `WeakValueDictionaries` as
caches can cause `removal` callbacks in rather harsh environments. Normal
`WeakValueDictionaries` remove keys with dead values by looking up the
key. This involves Python equality testing on the key, which can cause any
kind of operation in Sage. We need a dictionary where we can delete
entries without key comparisons. See below for possible strategies.
'''To the release manager:''' please fold this branch upon merging. There
is quite a bit of back-and-forth in the history of this branch that is not
very instructive to have in the global history of sage.
--
Comment:
Good to go for me! Incidentally, we're running into something I can only
explain as an illegal optimization in python's `print` command:
{{{
sage: from sage.misc.weak_dict import WeakValueDictionary
sage: D=WeakValueDictionary()
sage: D[1]=QQ
sage: print D
{1: <weakref at 0x34128f0; to 'RationalField_with_category' at 0x1ffb4d0>}
sage: repr(D)
'<WeakValueDictionary at 0x6225ae0>'
sage: str(D)
'<WeakValueDictionary at 0x6225ae0>'
}}}
and it's an odd optimization too. The only explanation I can see is that
`print` doesn't think `dict` can be subclassed and thus, based on a type
test, decides to use `PyDict` routines on it. I'm afraid that our solution
won't necessarily work in all places where a `UserDict` would get
recognized as a type that needs method resolution.
--
Ticket URL: <http://trac.sagemath.org/ticket/13394#comment:86>
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.