-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
perf: avoid repeat format in calc_func_dependencies_for_project #12305
Conversation
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.
Thanks @haohuaijin
.map(|i| vec![i]) | ||
.unwrap_or(vec![])), | ||
Expr::Alias(alias) => { | ||
let name = format!("{}", alias.expr); |
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.
Surprise that rust compile doesn't optimize on this 😮
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.
Maybe because the rust doesn't know the length of inputs_fields
at compile time, it doesn't optimize this case.
@@ -2793,22 +2793,28 @@ fn calc_func_dependencies_for_project( | |||
.filter_map(|(qualifier, f)| { | |||
let flat_name = qualifier | |||
.map(|t| format!("{}.{}", t, f.name())) | |||
.unwrap_or(f.name().clone()); | |||
.unwrap_or_else(|| f.name().clone()); |
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.
Arguments passed to unwrap_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrap_or_else, which is lazily evaluated.
👍
Which issue does this PR close?
Closes #12304
Rationale for this change
see #12304; the reason for the performance degradation is that we format the same expr in a loop.
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?