You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "haohuaijin (via GitHub)" <gi...@apache.org> on 2024/09/03 12:54:43 UTC
[PR] perf: avoid repeat format in calc_func_dependencies_for_project [datafusion]
haohuaijin opened a new pull request, #12305:
URL: https://github.com/apache/datafusion/pull/12305
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #12304
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: avoid repeat format in calc_func_dependencies_for_project [datafusion]
Posted by "lewiszlw (via GitHub)" <gi...@apache.org>.
lewiszlw commented on code in PR #12305:
URL: https://github.com/apache/datafusion/pull/12305#discussion_r1743309530
##########
datafusion/expr/src/logical_plan/plan.rs:
##########
@@ -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());
Review Comment:
> 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](https://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap_or_else), which is lazily evaluated.
👍
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: avoid repeat format in calc_func_dependencies_for_project [datafusion]
Posted by "haohuaijin (via GitHub)" <gi...@apache.org>.
haohuaijin commented on PR #12305:
URL: https://github.com/apache/datafusion/pull/12305#issuecomment-2326460754
the benchmarks are below, they compare main and this pr
<img width="904" alt="image" src="https://github.com/user-attachments/assets/138188b6-0399-4a79-9dca-1a5a40091919">
the below benchmarks are compared main, datafusion v41.0.0 and this pr
<img width="1132" alt="image" src="https://github.com/user-attachments/assets/c32c1ce5-682d-4782-8f84-0783132c5835">
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: avoid repeat format in calc_func_dependencies_for_project [datafusion]
Posted by "lewiszlw (via GitHub)" <gi...@apache.org>.
lewiszlw merged PR #12305:
URL: https://github.com/apache/datafusion/pull/12305
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: avoid repeat format in calc_func_dependencies_for_project [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #12305:
URL: https://github.com/apache/datafusion/pull/12305#discussion_r1743129397
##########
datafusion/expr/src/logical_plan/plan.rs:
##########
@@ -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());
input_fields.iter().position(|item| *item == flat_name)
})
.collect::<Vec<_>>(),
)
}
- Expr::Alias(alias) => Ok(input_fields
- .iter()
- .position(|item| *item == format!("{}", alias.expr))
- .map(|i| vec![i])
- .unwrap_or(vec![])),
- _ => Ok(input_fields
- .iter()
- .position(|item| *item == format!("{}", expr))
- .map(|i| vec![i])
- .unwrap_or(vec![])),
+ Expr::Alias(alias) => {
+ let name = format!("{}", alias.expr);
Review Comment:
Surprise that rust compile doesn't optimize on this 😮
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: avoid repeat format in calc_func_dependencies_for_project [datafusion]
Posted by "haohuaijin (via GitHub)" <gi...@apache.org>.
haohuaijin commented on code in PR #12305:
URL: https://github.com/apache/datafusion/pull/12305#discussion_r1743159777
##########
datafusion/expr/src/logical_plan/plan.rs:
##########
@@ -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());
input_fields.iter().position(|item| *item == flat_name)
})
.collect::<Vec<_>>(),
)
}
- Expr::Alias(alias) => Ok(input_fields
- .iter()
- .position(|item| *item == format!("{}", alias.expr))
- .map(|i| vec![i])
- .unwrap_or(vec![])),
- _ => Ok(input_fields
- .iter()
- .position(|item| *item == format!("{}", expr))
- .map(|i| vec![i])
- .unwrap_or(vec![])),
+ Expr::Alias(alias) => {
+ let name = format!("{}", alias.expr);
Review Comment:
Maybe because the rust doesn't know the length of `inputs_fields` at compile time, it doesn't optimize this case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org