Improve performance of BytePos #50392
Labels
C-cleanup
Category: PRs that clean code up or issues documenting cleanup.
I-compiletime
Issue: Problems and improvements with respect to compile times.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I have seen BytePos's operations showing up in profiles. In particular, common operations like to_usize() and from_usize() aren't getting inlined. Presumably this is because BytePos is in the libsyntax_pos crate but most of its uses are in other crates and it's not marked as
#[inline]
.Just as an experiment, I tried changing BytePos to just be a typedef of
u32
. Results were surprisingly good, with lots of improvements in the 1--4% range.It definitely seems worth doing something here. Though converting to
u32
is not good, because it's having BytePos be a newtype is definitely good for code readability.Would simply adding
#[inline]
or#[inline(always)]
to the relevant methods work? Does that have other consequences, such as increasing compile time of rustc itself?The text was updated successfully, but these errors were encountered: