You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Writable doesn't correctly count size of strings #52818
I think using Buffer.byteLength() when the decodeStrings is set to false is acceptable. Performance should be no worse than the default case (decodeStrings set to true) when the string is converted to a Buffer.
I think whenever we have a stream of strings and not buffers we should use byteLength (or just use Buffer.byteLength for everything) and if there is no performance impact land it.
(though byteLength would use its length as utf-8 and not utf-16 "as if it was a buffer encoded as utf-8" which may be desired?)
Activity
ronag commentedon May 3, 2024
@nodejs/streams @mcollina
lpinca commentedon May 3, 2024
I think we should fix it. Is this a recent regression?
benjamingr commentedon May 3, 2024
So the fix would be to call
Buffer.byteLength? Might be worth checking what the perf regression is and if it's not significant to fix it.benjamingr commentedon May 3, 2024
lpinca commentedon May 3, 2024
@benjamingr it seems to be correctly calculated in v10 and v0.10. See https://github.com/nodejs/node/blob/v10.x/lib/_stream_writable.js#L374 and https://github.com/nodejs/node/blob/v0.10/lib/_stream_writable.js#L204 (note
decodeChunk()).lpinca commentedon May 3, 2024
It actually seems to be correctly calculated also on main. See
node/lib/internal/streams/writable.js
Line 465 in 2c55652
lpinca commentedon May 3, 2024
Confirmed.
I think we can close this.
benjamingr commentedon May 3, 2024
@lpinca that's just one case though?
benjamingr commentedon May 3, 2024
To be clear:
This is across streams in several places - the fact writable works with decodeStrings set to true doesn't mean it's not a bug elsewhere?
lpinca commentedon May 3, 2024
The issue description did not mention the
decodeStringsoption. Yes, in that case the string size is incorrectly calculated.lpinca commentedon May 3, 2024
I think using
Buffer.byteLength()when thedecodeStringsis set tofalseis acceptable. Performance should be no worse than the default case (decodeStringsset totrue) when the string is converted to aBuffer.benjamingr commentedon May 3, 2024
I think whenever we have a stream of strings and not buffers we should use byteLength (or just use Buffer.byteLength for everything) and if there is no performance impact land it.
(though byteLength would use its length as utf-8 and not utf-16 "as if it was a buffer encoded as utf-8" which may be desired?)
doc: document watermark string behavior
doc: watermark string behavior
doc: watermark string behavior
doc: watermark string behavior
doc: watermark string behavior