Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMAQ superfluous copy #60

Open
nerdull opened this issue Oct 26, 2023 · 1 comment
Open

IMAQ superfluous copy #60

nerdull opened this issue Oct 26, 2023 · 1 comment

Comments

@nerdull
Copy link

nerdull commented Oct 26, 2023

Hi Alexey,

First of all, wonderful work on implementing interfaces to so many varieties of instruments!

I have especially benefited a lot from the IMAQ interface for my own project, where I need to interact with an NI PCIe-1433 frame grabber. Although it has been working smoothly, I have one suggestion regarding the performance enhancement. Specifically, I am referring to this line of code in IMAQ.py. The call to numpy.ndarray.copy() looks superfluous to me, as it only increases memory footprint and execution time. For a better performance, one can just return data. At least with my unexhaustive tests, this replacement works well. On the other hand, the gain is sizable, as now I can handle more throughput.

Cheers,
Xiangcheng

@AlexShkarin
Copy link
Owner

Thank you for the kind words!

As far as I remember, this line is required to have predictable behavior in some situations. Up until that point, data numpy array is directly mapped onto the acquisition ring buffer memory. Furthermore, in most cases its value will not get copied in the later code either (unless different frame axes indexing is used). Therefore, as soon as the buffer is cycled through and that frame is overwritten, the perceived values of data will change. Probably, most users do not expect that, but rather assume that the data received from the camera will stay constant.

That being said, I agree that if you intend to process the received frame right away (before it gets overwritten), this copying is not necessary, and it hurts perfromance. In the future, I will likely add an option to forego this copy operation (and similar ones done in other cameras) at the user's risk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants