Skip to content

Fix yet another memory leak caused by caching of coercion data #12313

@simon-king-jena

Description

@simon-king-jena

The following could not be fixed in #715:

sage: K = GF(1<<55,'t')
sage: for i in range(50):
....:     a = K.random_element()
....:     E = EllipticCurve(j=a)
....:     b = K.has_coerce_map_from(E)
....:     
sage: import gc
sage: gc.collect()
0

The problem is that any parent has a dictionary that stores any coerce map (and a different dictionary for conversion maps) ending at this parent. The keys are given by the domains of the maps. So, in the example above, the field K has an attribute that is a dictionary whose keys are the different elliptic curves.

In coercion, it is usually best to compare parents not by equality but by identity. Therefore, I suggest to implement a container called MonoDict that works similar to the new weak TripleDict (see #715), but takes a single item as a key.

First tests show that one can actually gain a lot of speed: MonoDict can access its items much faster than a usual dictionary.

Apply

Depends on #715
Depends on #11521
Depends on #12215
Depends on #13746
Depends on #13378
Depends on #13387

Dependencies: #715, #11521, #12215, #13746, #13378; merge with #13387

CC: @jpflori @vbraun @robertwb @alexanderdreyer @sagetrac-PolyBoRi @nthiery

Component: memleak

Keywords: coercion weak dictionary

Author: Simon King, Jean-Pierre Flori

Reviewer: Simon King, Jean-Pierre Flori, John Perry, Nils Bruin

Merged: sage-5.8.beta2

Issue created by migration from https://trac.sagemath.org/ticket/12313

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions