Skip to content

Inefficiency in copying PARI objects to the heap #14817

@pjbruin

Description

@pjbruin

When PARI objects are wrapped into Python objects, they are copied from the PARI stack to a malloc'ed memory block. This is done by the function deepcopy_to_python_heap() in sage/libs/pari/gen.pyx. To determine how much memory to allocate, this function creates a dummy copy on the stack and measures by how much the stack pointer goes down. This is inefficient and can be improved by calling PARI's gsizebyte() function, which does exactly what we want.

Also, copying the object to the malloc'ed block is done inelegantly by temporarily changing the global variables top, bot and avma defining the PARI stack. Again, there is a PARI function that does what we want: gcopy_avma() does the same as gcopy(), but copies to a user-specified address.

I am attaching a patch that replaces deepcopy_to_python_heap() by a simpler and faster implementation. (It also deletes a comment that seems to refer to code that no longer exists.)

Apply: attachment: trac14817-copy_pari_objects.patch

CC: @jpflori

Component: performance

Author: Peter Bruin

Reviewer: Volker Braun

Merged: sage-5.12.beta0

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions