On Monday, March 12, 2018 at 9:58:39 AM UTC, Jeroen Demeyer wrote:
>
> There is some very bad behaviour related to CachedRepresentation caching 
> that I'm observing on #24742 (but this is otherwise unrelated to that 
> ticket): 
>
> sage: timeit('MatrixSpace(ZZ,3,3)') 
> 625 loops, best of 3: 117 µs per loop 
>
> Now, we try again but we first create a strong reference: 
>
> sage: S = MatrixSpace(ZZ,3,3) 
> sage: timeit('MatrixSpace(ZZ,3,3)') 
> 625 loops, best of 3: 4.13 µs per loop 
>
> This is much faster the second time! In the first example, the caching 
> of CachedRepresentation.__classcall__ is pointless since there is no 
> strong reference to the entry in the cache, so it gets deleted 
> immediately whenever the "MatrixSpace(ZZ,3,3)" is deleted. 
>
> This is just the usual Py_DECREF of Python objects, it has nothing to do 
> with the cyclic garbage collector: the behaviour remains the same even 
> with gc.disable(). 
>
> This makes me think that we might need a version of CachedRepresentation 
> which keeps semi-strong references: these would only be deleted by the 
> cyclic garbage collector but not by a simple Py_DECREF(). 
>
> This is extremely easily done: let the object store a reference to itself. 
That makes it part of a cycle, and hence a decref won't delete it.

It doesn't sound like the right solution to me though: if you think the 
system benefits from keeping certain recently constructed objects around, 
they should probably be part of an LRU cache.

Your example doesn't convince me at all that we need this change though. 
You should only consider making a change if you have a real-world example 
that would significantly benefit and if you can show that degradation in 
other normal use is minimal. A simplistic "timeit" statement, although 
instructive, does not necessarily illustrate real-world usage.

I'm happy to see certain objects are now quickly disappearing from memory! 
we usually have the opposite problem, and that really grinds things to a 
halt.
 

>
> Jeroen. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" 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 https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to