perf(codegen): speed up printing StringLiterals#10046
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #10046 will create unknown performance changesComparing Summary
Benchmarks breakdown
|
248c62a to
9da8106
Compare
93d7896 to
687f8bf
Compare
9da8106 to
c69b887
Compare
c69b887 to
96a803b
Compare
96a803b to
ff181cc
Compare
b6529c8 to
699ade4
Compare
|
I don't want you to go down the rabbit hole ... but we can probably avoid looping through the string twice by storing the position of the "unknown" values, and change them at the end of the loop. |
Merge activity
|
699ade4 to
e44b613
Compare
ff181cc to
84c33ba
Compare
|
As a test, I tried the shortcut of just printing So basically, I think there's very little gain in trying to optimize it any further. We might get 0.1% perf improvement at best. It was probably a waste of time even going as far as I have in this PR! |
fd663ec to
4984b06
Compare
a898510 to
021986e
Compare
bc8214f to
08b18d4
Compare
08b18d4 to
84a22c2
Compare
021986e to
daee98a
Compare
|
This is finally ready to merge. |
|
@Boshen I assume the effect on formatter benchmarks is just noise? |
84a22c2 to
d94d261
Compare
daee98a to
2f58955
Compare
Speed up printing `StringLiteral`s by: * Iterating over the string byte-by-byte, not char-by-char. * Not using a peekable iterator. * Printing string in chunks. * Using a lookup table for bytes that need escaping. * Minimizing the amount of code in the hot loop. * Calculating the quote character to use lazily. * Faster calculation of quote character when backtick cannot be used as quote. In common case where string contains no bytes that need escaping, the string will be written to output buffer in one shot, and there's no need for an extra pass through the string's bytes to decide on the quote character to use.
2f58955 to
7672620
Compare
d94d261 to
775abac
Compare

Speed up printing
StringLiterals by:In common case where string contains no bytes that need escaping, the string will be written to output buffer in one shot, and there's no need for an extra pass through the string's bytes to decide on the quote character to use.