Skip to content

Do not overuse copy_to_buffer #944

@dachengx

Description

@dachengx

def copy_to_buffer(

There are many cases where copy_to_buffer will be used, but not all of them the copy_to_buffer is necessary. It is not necessary in particular one case:

  1. We do not need source after "copying".
  2. The fields of buffer is a subset of source.

In this case, numpy.lib.recfunctions.drop_fields is a better choice. Because we can directly overwrite source without worrying. Using drop_fields can help us save memory usage because there will be only one copy of the array existing in memory.

from numpy.lib.recfunctions import drop_fields

An example of this case is https://github.com/XENONnT/straxen/blob/5bb4e0494d02424ffb0563f758c6ffb644dfe4d8/straxen/plugins/records/records.py#L170-L171.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions