Optimize `rustc_lexer` by Julian-Wollersberger · Pull Request #91393 · rust-lang...

 9 months ago
source link: https://github.com/rust-lang/rust/pull/91393
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.


The cursor.first() method in rustc_lexer now calls the chars.next() method instead of chars.nth_char(0).

This allows LLVM to optimize the code better. The biggest win is that eat_while() is now fully inlined and generates better assembly. This improves the lexer's performance by 35% in a micro-benchmark I made (Lexing all 18MB of code in the compiler directory). But lexing is only a small part of the overall compilation time, so I don't know how significant it is.

Big thanks to criterion and cargo asm.

About Joyk

Aggregate valuable and interesting links.
Joyk means Joy of geeK