Prevent unnecessary memory copying in nvwave#19791
Prevent unnecessary memory copying in nvwave#19791gexgd0419 wants to merge 3 commits intonvaccess:masterfrom
Conversation
| NVDAHelper.localLib.wasPlay_feed( | ||
| self._player, | ||
| data, | ||
| cast(data, c_char_p), |
There was a problem hiding this comment.
I think it's better to keep the cast out of the wasPlay_feed call, otherwise it is hard to track issues caused by cast failures.
SaschaCowley
left a comment
There was a problem hiding this comment.
This change would have been made due to a ctypes type incompatibility, but I don't remember the specific trigger. I'll see if I can find it, because I am reasonably sure I tried this and it didn't work.
| data = string_at(data, size) | ||
| # wasPlay_feed requires c_char_p, so cast data to c_char_p before calling. | ||
| # Casting bytes to c_char_p is also fine, as long as the original data is not released. | ||
| dataptr = cast(data, c_char_p) |
There was a problem hiding this comment.
Is there a reason not to perform this cast directly in the call to wasapi.wasPlay_feed?
There was a problem hiding this comment.
See comment from @LeonarddeR :
I think it's better to keep the cast out of the
wasPlay_feedcall, otherwise it is hard to track issues caused by cast failures.
|
I tried the launcher built by GitHub Actions. At least all the built-in synths work on my system. Before the 64-bit transition, After searching the codebase, I found those possible data types for the
And casting to I might need to dig deeper. |
|
@SaschaCowley Or what about changing the Using
Wave buffers can be an array of raw bytes, or an array of 16-bit samples, but actually we don't care about the exact "data type", we just want to send the raw bytes to the system. If we use |
This comment was marked as outdated.
This comment was marked as outdated.
|
@gexgd0419 - is this ready for review? |
|
I think this was waiting on me to try and find why we went with this approach in the first place. Unfortunately I've lost that branch, so I'm not sure. |
Link to issue number:
None
Summary of the issue:
#18207 introduced these two lines in
nvwave.py:string_atcreates another copy of the data buffer stored asbytes, which is not needed, since it will only be passed towasPlay_feed. As many built-in synths pass inc_void_por actypearray instead ofbytes, this would create a lot of unnecessary memory copies.datashould be passed towasPlay_feeddirectly if possible.As it turned out, those two lines were added because of the
argtypesset forwasPlay_feed:c_void_pcannot be implicitly converted toc_char_p, sostring_atwas added as a fix.Description of user facing changes:
None.
Description of developer facing changes:
None.
datastill accepts anything convertible toc_void_pandbytes.Description of development approach:
This PR chooses another way to fix that problem: cast
datatoc_char_pexplicitly. Anything that can be converted toc_void_pcan be converted toc_char_pthis way, includingc_void_p,bytes, andctypesarray.Testing strategy:
Tested manually.
Known issues with pull request:
None
Code Review Checklist: