perf(pg-protocol): decode short ascii values without buffer.toString() - #3773
Closed
nigrosimone wants to merge 1 commit into
Closed
nigrosimone wants to merge 1 commit into
nigrosimone wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every field of every row goes through
BufferReader.string(), which callsbuffer.toString('utf-8'). That call has a fixed cost in the C++ boundary that is bigger than the decoding itself when the value is short, and most values in a result set are short: ids, flags, small numbers, dates.So for values up to 16 bytes that are all ASCII the string is now built with
String.fromCharCode. Anything longer, or with a byte above 127, still goes tobuffer.toString().Parser only, 500 rows per message, median of 5 runs on node 26 (ms, lower is better):
End to end on localhost,
SELECTof 5000 rows, 5 short columns: 9.1ms -> 6.7ms per query.The test in
inbound-parser.test.tsparses a data row with a value of every length from 0 to 19 plus accented, chinese and emoji values, and fails if the ascii check is removed.