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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: Support copy-on-write in TypedArrays #707
Conversation
Handles TypedArrays with the same underlying buffer, so the buffer is copied only once. Limitations: * No patch support * TypedArray.subarray does not return a draft Possible optimizations: 1. Not copying when a value is set to the same number
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 1f70360:
|
I have just noticed a mistake: I'll add a test to ensure that those work and try to fix those |
Fixes most problems from the previous approach
I have added a few more tests and commits, and changed the approach for what the proxy target should be in the case of typed arrays. I believe it should behave as expected I'm looking forward to receiving feedback 馃檪 |
Sorry, currently not having a lot of bandwidth. Since this is quite a meaty change, probably will only review it in January or something, hope that isn't too much of a problem. |
@mweststrate Sure, no problem 馃檪 Take your time |
Closing as this feature never landed |
I don't mind not having this feature in immer. I am wondering what do you mean by saying that this feature never landed. What feature never landed? |
This PR :) |
Oh. It is disappointing to see a PR closed because it was not merged without any more justification. Especially that there was no delay and no asks from me at any point. I feel like my time was wasted. #696 is not closed and still encourages implementing this idea. |
Yeah sorry about that! Currently Immer has 5 million dependent packages on Github, and the idea has 3 upvotes, so it seems hard to justify at this moment to ship the additional code and increased maintenance complexity to everyone. At this moment it'd become a classic example of feature creep I think :) |
Sure, makes sense, thanks for a more thorough explanation 馃憤 |
This is an attempt to fix #696
This MR adds support for copy-on-write for TypedArrays (e.g.
Uint16Array
).It correctly handles TypedArrays with the same underlying
ArrayBuffer
, so when copying 2 arrays with the same underlying buffer, the drafts will also have the same underlying buffer.I was not sure how to handle ProxyTypes and Archtypes, so feel free to suggest another way to handle those. Also, do not hesitate listing things I could have done better 馃檪
Limitations
I did not spend enough time to fix those. The known limitations/missing features are:
Possible optimizations
Testing
Aside from the added automated tests, I did not test this feature extensively.