-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
chore: use const fn in Span #10320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
chore: use const fn in Span #10320
Conversation
|
CodSpeed Performance ReportMerging #10320 will degrade performances by 2.42%Comparing Summary
Benchmarks breakdown
|
self.lo | ||
} | ||
|
||
#[inline] | ||
pub fn new(mut lo: BytePos, mut hi: BytePos) -> Self { | ||
if lo > hi { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually #9962 is about removing this swap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. But I have two questions:
• Does this change break existing code?
• Should we add assert!(lo < hi)
or debug_assert!(lo < hi)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes for the first question. (It’s a bug IMO)
And debug assert would be enough considering the number of parser tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crates/swc_common/src/syntax_pos.rs
Outdated
if lo > hi { | ||
std::mem::swap(&mut lo, &mut hi); | ||
pub const fn new(lo: BytePos, hi: BytePos) -> Self { | ||
if lo.0 > hi.0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be removed and callers should be fmodified to call Span::new with correct argument
The latest benchmark report doesn’t show any regressions (I’m guessing it’s just some noise in the Not sure why the @kdy1 What do you think? Should we keep pursuing this change? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of this PR?
swap operation is not removed at all...
Description:
Using
const fn
can generally help lower both runtime overhead.BREAKING CHANGE:
nothing.
Related issue (if exists):
Fixes #9962