Skip to content

Reduce the overhead of using procedures in Singular #410

Open
@zickgraf

Description

@zickgraf

Currently, using procedures in Singular causes overhead:

  1. When calling a procedure, the arguments are copied, and
  2. when returning multiple values, the values have to be copied (twice in the current implementation, Return list expressions instead of lists in Singular #409 reduces this to one copy).

This causes unexpected peak RAM usage and slowdowns, noticeable for large (say, 10000x10000) matrices.

There are multiple possible solutions/improvements:

  1. Get rid of aliases. For example, SyzForHomalg and SyzygiesGeneratorsOfRows seem to be aliases.
  2. Inline some procedure calls in Singular.gi. For example, DecideZeroColumns could directly call reduce instead of calling DecideZeroRows.
  3. Do not use procedures at all but put the code directly into SingularBasic.gi.
  4. Use references to avoid the copies: https://www.singular.uni-kl.de/Manual/4-2-0/sing_200.htm#SEC240 References are a feature marked as experimental, but since we would use them in a very basic way, we might be safe?
  5. Talk to the Singular people about some way to pass arguments by reference and some way to avoid copies when returning multiple values (for single values there actually is some logic preventing unnecessary copies).

As always, there are obvious pros and cons :D

Edit: I just noticed that even kernel functions (e.g. module) and syntactic structures (see example below) have a similar overhead. So I'm not sure if it really makes sense to invest time here.
Example:

ring R;
matrix A[10000][10000];
matrix B[10000][10000];
matrix C[20000][10000] = A,B;

During the computation of C there is a noticeable peak in RAM usage. I assume this is also due to copying some stuff internally stuff.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions