Details
-
Task
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
None
-
None
Description
String parameters sent with the text protocol are escaped by a per-character JavaScript loop in PacketOutputStream.writeUtf8StringEscapeQuote, whatever the string. Most strings contain nothing to escape, and for those the loop only re-implements what Buffer.write does natively.
When a string is 32 chars or longer and indexOf finds no quote, backslash or NUL, write it with the native encoder. Shorter strings and strings that need escaping keep the current loop. Apply the same check to the NO_BACKSLASH_ESCAPES branch, which byte-loops over the encoded buffer.
Measured against the current loop on Node.js 22: 3x at 128 chars, 12x at 512, 38x at 4 KB for ASCII, 2x for CJK text. No cost for strings that do need escaping.