perf(codegen): reduce checks printing strings#10341
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 #10341 will not alter performanceComparing Summary
|
|
Tiny effect on benchmark, because strings are a small part of AST, and this change probably only affects printing escapes. In the hot loop where no escape required, compiler probably already deduced there was definitely a byte to consume, because we just peeked it a few instructions earlier. |
|
Tiny optimization, so merging without review. |
Merge activity
|
Speed up printing strings. I had wrongly assumed that `bytes.next().unwrap_unchecked()` would skip checks, but it seems it behaves the same as `bytes.next()` - i.e. check iterator is not empty, and only advance if it's not. Use `assert_unchecked!` instead to inform compiler that there are definitely the required number of bytes remaining in `bytes` iterator before consuming them. This reduces instruction count considerably, and removes a branch on every byte consumed. https://godbolt.org/z/TWzfK1eKj The mysteries of the compiler!
3d0cf25 to
426f8cb
Compare

Speed up printing strings.
I had wrongly assumed that
bytes.next().unwrap_unchecked()would skip checks, but it seems it behaves the same asbytes.next()- i.e. check iterator is not empty, and only advance if it's not.Use
assert_unchecked!instead to inform compiler that there are definitely the required number of bytes remaining inbytesiterator before consuming them.This reduces instruction count considerably, and removes a branch on every byte consumed.
https://godbolt.org/z/TWzfK1eKj
The mysteries of the compiler!