Skip to content

Better GMP integration with the GC #11202

@carnaval

Description

@carnaval

We discussed this a few times so better file an issue in case anyone wants to go ahead.

For now our GMP integration allocates the dynamic memory holding the integer using the libc allocator. It then adds a finalizer for cleanup when the parent object gets GCd.

This is inefficient, mainly because finalizers themselves are, and because the GC can't know of much memory will be freed by a collection before running the finalizers, which makes some heuristics bad. The best I can come up with for doing this would be to allow julia datatypes to have fields of type buff_t, like the hidden data pointer in an Array. Those fields points to gc memory which is not tagged but can have variable length. The BigInt type could then declare the _mp_d field (https://gmplib.org/manual/Integer-Internals.html) as a buff_t and allocate it using allocb. This should not require modification inside GMP. It would however need to special case fields of buffer type in the DataType marking code in the gc.

I don't know much about GMP so maybe there is a better solution. Also this would probably work for MPFR and maybe other C libraries we are wrapping using finalizers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GCGarbage collectorbignumsBigInt and BigFloatperformanceMust go faster

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions