On Wednesday, January 28, 2015 at 12:03:00 AM UTC-8, vdelecroix wrote: > This is really annoying from the user perspective
Not nearly as annoying as the unavoidable memory leaks we had before, though. Note that most internal structure types do not suffer from slowdowns, so you could study them to see what the difference is for keeping those homsets alive. (and it might also > be related to the infinitely longer TestSuite(M) that I mentioned > above). Quite possibly. Profiling would be quite useful. Do you have an idea for a mechanism that would make this > automatic ? > I mean while doing > > sage: P = ProductRing((GF(5), GF(5))) > > I would like that all important coercions to be kept alive until P > dies. It might be something explicit in the constructor of > ProductRing. Would the following of good practice within Sage: > > class ProductRing(Parent): > def __init__(self, ...): > ... > self._cache = [self.coerce_map_from(GF(5))] > No. The coercion system has a cache of its own. It does keep strong references to the coercion maps. They don't have homsets, though. The problem might be that you keep extracting coercion maps from the coercion system: if all(R.has_coerce_map_from(S) for R in self._rings): return CallableConvertMap(S, self, lambda x: self.element_class(tuple(R.coerce_map_from(S)(x) for R in self._rings), parent=self), parent_as_first_arg=False) If you rewrite this as: if all(R.has_coerce_map_from(S) for R in self._rings): coerce_maps = tuple( R.coerce_map_from(S) for R in self._rings) return CallableConvertMap(S, self, lambda x: self.element_class( tuple(m(x) for m in coerce_maps), parent=self), parent_as_first_arg=False) is a lot faster. Now the lifetime of the homsets is tied (via storing them in a closure) to the lifetime of the coercion map that needs them, and the coercion system itself can cache that map for as long as needed. There are other ways of writing this that are probably even faster. I would imagine that lambda x: self.element_class( tuple( R(x) for R in self._rings),parent=self) would be even faster (and possibly more memory efficient, because now everything is left to the coercion system instead of trying to extract information from the coercion system in the form of maps). -- 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 sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.