[sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-12 Thread Simon King
Hi Jeroen, On 2018-03-12, Jeroen Demeyer wrote: > 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

[sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-12 Thread Simon King
On 2018-03-12, Simon King wrote: > Hi Jeroen, > > On 2018-03-12, Jeroen Demeyer wrote: >> 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 mi

[sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-12 Thread Nils Bruin
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: 11

[sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-12 Thread Simon King
On 2018-03-12, Nils Bruin wrote: > 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 sim

[sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-13 Thread Simon King
Hi Dima, On 2018-03-13, Dima Pasechnik wrote: > On Tuesday, March 13, 2018 at 8:37:49 AM UTC, Jeroen Demeyer wrote: >> I can imagine a small function constructing a matrix (for which it needs >> to construct the MatrixSpace) to do some computation but not keeping >> that matrix in memory. For e

Re: [sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-13 Thread Jeroen Demeyer
On 2018-03-12 23:07, Nils Bruin wrote: 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 simplis

Re: [sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-13 Thread Dima Pasechnik
On Tuesday, March 13, 2018 at 8:37:49 AM UTC, Jeroen Demeyer wrote: > > On 2018-03-12 23:07, Nils Bruin wrote: > > 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

Re: [sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-13 Thread Nils Bruin
On Tuesday, March 13, 2018 at 9:38:05 AM UTC, Dima Pasechnik wrote: > > > >> I can imagine a small function constructing a matrix (for which it needs >> to construct the MatrixSpace) to do some computation but not keeping >> that matrix in memory. For example, the output of that function could

Re: [sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-13 Thread Erik Bray
On Tue, Mar 13, 2018 at 9:36 AM, Jeroen Demeyer wrote: > On 2018-03-12 23:07, Nils Bruin wrote: >> >> 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

Re: [sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-13 Thread Nils Bruin
On Tuesday, March 13, 2018 at 11:14:41 AM UTC, Erik Bray wrote: > > > Doesn't Sage allow creating mutable matrices? In a case like that you > should mutate the object rather than go through expensive object > creation over and over. > I think the scenario would be one where the discriminant of

Re: [sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-13 Thread Jeroen Demeyer
On 2018-03-13 10:38, Dima Pasechnik wrote: this example, assuming the matrix size is a parameter, would easily become a memory leak You mean with my code from #24954? My idea is to cache strongly only a fixed finite number (currently 128) of CachedRepresentation instances. So even if you crea

Re: [sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-13 Thread Jeroen Demeyer
On 2018-03-13 12:00, Nils Bruin wrote: you'd be making life harder for the memory cache of the processor. IMHO, if you worry about that, you shouldn't be writing Python. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this g

Re: [sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-13 Thread Erik Bray
On Tue, Mar 13, 2018 at 12:43 PM, Nils Bruin wrote: > On Tuesday, March 13, 2018 at 11:14:41 AM UTC, Erik Bray wrote: >> >> >> Doesn't Sage allow creating mutable matrices? In a case like that you >> should mutate the object rather than go through expensive object >> creation over and over. > > >

Re: [sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-13 Thread Erik Bray
On Tue, Mar 13, 2018 at 2:02 PM, Jeroen Demeyer wrote: > On 2018-03-13 12:00, Nils Bruin wrote: >> >> you'd be making life harder for the memory cache of the processor. > > > IMHO, if you worry about that, you shouldn't be writing Python. While I definitely agree with that statement 100% in princ

Re: [sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-13 Thread Erik Bray
On Tue, Mar 13, 2018 at 1:58 PM, Jeroen Demeyer wrote: > On 2018-03-13 10:38, Dima Pasechnik wrote: >> >> this example, assuming the matrix size is a parameter, would easily >> become a memory leak > > > You mean with my code from #24954? My idea is to cache strongly only a fixed > finite number (

Re: [sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-13 Thread Jeroen Demeyer
On 2018-03-13 14:42, Erik Bray wrote: But it sounds like that's more or less what Jeroen is proposing (as long as it's not caching matrices by value?) I'm not caching the Element (Matrix) but the Parent (MatrixSpace). -- You received this message because you are subscribed to the Google Groups

Re: [sage-devel] Re: WeakValueDictionary: items are deleted too soon

2018-03-13 Thread Erik Bray
On Tue, Mar 13, 2018 at 3:10 PM, Jeroen Demeyer wrote: > On 2018-03-13 14:42, Erik Bray wrote: >> >> But it >> sounds like that's more or less what Jeroen is proposing (as long as >> it's not caching matrices by value?) > > > I'm not caching the Element (Matrix) but the Parent (MatrixSpace). Grea