-
Notifications
You must be signed in to change notification settings - Fork 18
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
Shouldn't we use TypedArray.set instead of a for loop for copying arraybuffers? #22
Comments
We can in some capacity. The problem is that we need to copy part of a
The way to do this in JavaScript is to take a This is not enough to express all what's needed for this ring buffer:
We can make it so When running the test suite (which is admittedly a bit contrived, with workloads that aren't that realistic), this fast-path can be taken in about 28% of the We can also add two new methods that always use |
If anybody can try this PR on a "real" workload and can report results, I'd be happy to have a look at the data. |
Ah that makes sense. While I believe one way around this is to not make wrapping pushes that would require a 2 separate pushes onto the ringbuffer. Instead an artificial end pointer would be set and we would write to the beginning of the ringbuffer (given there is enough room). Then the artificial end pointer could be cleared after the read pointer passes it. This would create some "wasted" space at the end of the ringbuffer but given the 4x - 15x copy time improvement it may be worth if for some fantasy work load I can't think of right now lol. However this is most likely out of the scope of this library and I'm not sure if the complexity is worth it, but is interesting to think about. Thank you for your "fast path" additions. |
Set is much faster, even on small arrays.
Code in question:
ringbuf.js/js/ringbuf.js
Lines 346 to 350 in 016d963
Benchmark:
input
is 10,000 F32, andsubInput
is 100 F32.The text was updated successfully, but these errors were encountered: