Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upCloneArrayBuffer copies the underlying ArrayBuffer until the end, which callers don't need #447
Comments
bterlson
added
the
question
label
Mar 3, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
@allenwb @kmiller68 @leobalter What do you think about this issue? |
added a commit
to littledan/ecma262
that referenced
this issue
Mar 4, 2016
littledan
referenced this issue
Mar 4, 2016
Merged
In the TypedArray(typedArray) constructor, copy only the needed portion #458
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
leobalter
Mar 4, 2016
Member
Would it make sense to change the TypedArray constructor definition to not allocate and keep around this extra memory?
Your commit (8a60672) seems interesting and helps looking through this issue.
Currently, it seems the new clone is limited to the expected src buffer bytelength as in steps 8 and 11 on CloneArrayBuffer, eliminating the excess from the offset.
8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, cloneLength).
On your changes, you also limit these changes to the bytelength of the typedArray, eliminating the remaining unused buffer bytelength after the typedArray bytelength is considered.
That seems reasonable and indeed might avoid extra memory use, especially in case you have a subarray sample.
Your commit (8a60672) seems interesting and helps looking through this issue. Currently, it seems the new clone is limited to the expected src buffer bytelength as in steps 8 and 11 on CloneArrayBuffer, eliminating the excess from the offset.
On your changes, you also limit these changes to the bytelength of the typedArray, eliminating the remaining unused buffer bytelength after the typedArray bytelength is considered. That seems reasonable and indeed might avoid extra memory use, especially in case you have a subarray sample. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
littledan
Mar 4, 2016
Member
@leobalter Exactly. To clarify from the spec text, see the way that cloneLength is calculated:
6 . Let cloneLength be srcLength - srcByteOffset.
The early end is not taken into account, only the offset.
|
@leobalter Exactly. To clarify from the spec text, see the way that cloneLength is calculated:
The early end is not taken into account, only the offset. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
allenwb
Mar 4, 2016
Member
I agree, this is a bug. The fast path should not produce a buffer with extra space.
Personally, I'd fix it by adding a cloneLength parameter to CloneArrayBuffer
|
I agree, this is a bug. The fast path should not produce a buffer with extra space. Personally, I'd fix it by adding a cloneLength parameter to CloneArrayBuffer |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
added a commit
to littledan/ecma262
that referenced
this issue
Mar 9, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
littledan
Mar 9, 2016
Member
The new version is intended to address these concerns. Any thoughts? Thanks for the feedback.
|
The new version is intended to address these concerns. Any thoughts? Thanks for the feedback. |
littledan commentedMar 1, 2016
The TypedArray constructor includes a fast path for a TypedArray input (as opposed to treating it as an iterable), which has a fast path for the case of the same-type input and output. This calls CloneArrayBuffer. CloneArrayBuffer takes an argument for the start offset, but not for the end, so it copies the underlying ArrayBuffer until the end. Then, the caller sets the [[ArrayLength]] appropriately so that it gets the right length array. However, the underlying ArrayBuffer is still accessible through
get %TypedArray%.prototype.buffer, so the extra unnecessary allocation is observable. Would it make sense to change the TypedArray constructor definition to not allocate and keep around this extra memory?