ni / ni/nidaqmx-python

read_waveform spends too much time constructing hightime objects

Open
#844 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
592
Forks
199
Avg merge
1d 16h
Merged PRs (30d)
10

Description

Profile results for read_waveform indicate that constructing hightime objects is a bottleneck. These profile results include the proposed fix for #843.

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    73707    0.080    0.000   14.231    0.000 D:\dev\nidaqmx-python\generated\nidaqmx\_feature_toggles.py:148(wrapper)
       18    0.000    0.000   11.648    0.647 D:\dev\nidaqmx-python\tests\benchmark\test_analog_stream_readers.py:78(test___analog_multi_channel_reader___read_waveform)
    51991    0.252    0.000   10.998    0.000 D:\dev\nidaqmx-python\generated\nidaqmx\stream_readers\_analog_multi_channel_reader.py:140(read_waveforms)
    51991    0.314    0.000   10.247    0.000 D:\dev\nidaqmx-python\generated\nidaqmx\_library_interpreter.py:6416(read_analog_waveforms)
     3802    0.126    0.000    6.975    0.002 D:\dev\nidaqmx-python\generated\nidaqmx\_library_interpreter.py:6637(_set_waveform_timings)
    24366    0.722    0.000    6.624    0.000 D:\dev\nidaqmx-python\.venv\lib\site-packages\hightime\_timedelta.py:43(__new__)
        6    0.000    0.000    4.122    0.687 D:\dev\nidaqmx-python\generated\nidaqmx\_library_interpreter.py:6514(_internal_read_analog_waveform_per_chan)
     6090    0.062    0.000    3.417    0.001 D:\dev\nidaqmx-python\.venv\lib\site-packages\hightime\_datetime.py:294(__add__)
       24    0.000    0.000    2.883    0.120 D:\dev\nidaqmx-python\generated\nidaqmx\task\_task.py:1254(wait_until_done)
       24    2.883    0.120    2.883    0.120 D:\dev\nidaqmx-python\generated\nidaqmx\_library_interpreter.py:5961(wait_until_task_done)
    21716    0.055    0.000    2.863    0.000 D:\dev\nidaqmx-python\generated\nidaqmx\stream_readers\_analog_single_channel_reader.py:112(read_waveform)
  1878658    1.887    0.000    2.848    0.000 C:\Users\Administrator\.pyenv\pyenv-win\versions\3.9.13\lib\fractions.py:62(__new__)
    21716    0.105    0.000    2.784    0.000 D:\dev\nidaqmx-python\generated\nidaqmx\_library_interpreter.py:6374(read_analog_waveform)
414236/219308    0.204    0.000    1.808    0.000 {built-in method builtins.round}
     6090    0.020    0.000    1.698    0.000 D:\dev\nidaqmx-python\.venv\lib\site-packages\hightime\_timedelta.py:221(__add__)
414222/219294    0.543    0.000    1.695    0.000 C:\Users\Administrator\.pyenv\pyenv-win\versions\3.9.13\lib\fractions.py:505(__round__)
   131574    0.256    0.000    1.544    0.000 D:\dev\nidaqmx-python\generated\nidaqmx\_library_interpreter.py:6615(_invoke_callback)

Originally posted by @bkeryan in https://github.com/ni/nidaqmx-python/pull/842#discussion_r2380634836

AB#3330698

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/benchmark/test_analog_stream_readers.py and the profiled read_waveforms, read_waveform, read_analog_waveforms, and _set_waveform_timings entries in generated/. Profile the benchmark to identify the hightime object construction path, then verify that the benchmark shows reduced time for waveform reads without changing their results.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.