You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2024/05/11 11:07:50 UTC
Re: [PR] refactor: use Reduce string allocations in Expr::display_name (use write instead of format!) [datafusion]
alamb commented on code in PR #10454:
URL: https://github.com/apache/datafusion/pull/10454#discussion_r1597426402
##########
datafusion/expr/src/expr.rs:
##########
@@ -1654,28 +1654,42 @@ fn fmt_function(
write!(f, "{}({}{})", fun, distinct_str, args.join(", "))
}
-fn create_function_name(fun: &str, distinct: bool, args: &[Expr]) -> Result<String> {
- let names: Vec<String> = args.iter().map(create_name).collect::<Result<_>>()?;
- let distinct_str = match distinct {
- true => "DISTINCT ",
- false => "",
- };
- Ok(format!("{}({}{})", fun, distinct_str, names.join(",")))
+fn write_function_name<'a>(
+ w: &'a mut (dyn Write + 'a),
Review Comment:
Rather than using dynamic dispatch I think you can make this just a normal generic function and make the code simpler and likely more performant
Something like
```rust
fn write_function_name<W: Write>(
w: &mut W,
```
I actually tried it locally and it seems to work well. Here is a PR https://github.com/erratic-pattern/arrow-datafusion/pull/1 to this branch for your consideration
##########
datafusion/expr/src/expr.rs:
##########
@@ -1717,111 +1732,118 @@ pub(crate) fn create_name(e: &Expr) -> Result<String> {
if let Some(char) = escape_char {
format!("CHAR '{char}'")
} else {
- "".to_string()
+ "".to_owned()
Review Comment:
same comment as above -- let's get rid of all the extra allocations
##########
datafusion/expr/src/expr.rs:
##########
@@ -1693,10 +1708,9 @@ pub(crate) fn create_name(e: &Expr) -> Result<String> {
if let Some(char) = escape_char {
format!("CHAR '{char}'")
} else {
- "".to_string()
+ "".to_owned()
Review Comment:
I think you could avoid this allocation (and the `format!` above it).
--
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