tc39 / proposal-arraybuffer-base64

TC39 proposal for Uint8Array<->base64/hex
https://tc39.github.io/proposal-arraybuffer-base64/
MIT License
248 stars 8 forks source link

performance of Uint8Array.prototype.setFrom{Base64,Hex} #57

Closed phoddie closed 1 month ago

phoddie commented 5 months ago

The excellent notes from @anba on additional tests made me realize that XS does not implement these methods as expected by the spec text.

Uint8Array.prototype.setFrom{Base64,Hex} doesn't modify the typed array when the input string is invalid.

My recollection is that BYOB was proposed by @syg as a performance optimization. Requiring full validation of the input before modifying the output reduces the performance gain: either two full passes over the source data are necessary or a temporary buffer is needed to store the decoded data before updating the destination.

If leaving the destination unmodified for invalid input takes priority, that's fine. But, since performance was the motivator, I want to check before making changes. I couldn't find previous discussion about this tradeoff.

bakkot commented 5 months ago

I originally wrote it this way because it's more consistent with a general philosophy of "validate the input, then process it", but it does seem wasteful to require a second pass or temp buffer, especially in the common case of valid input. I don't think there was any discussion of this.

I'll put an item on the agenda for the next meeting.

bakkot commented 5 months ago

PR: https://github.com/tc39/proposal-arraybuffer-base64/pull/58

bakkot commented 1 month ago

Done in https://github.com/tc39/proposal-arraybuffer-base64/pull/58, tests in https://github.com/tc39/test262/pull/4133.