Skip to content

Conversation

@sundy-li
Copy link
Member

@sundy-li sundy-li commented Jan 7, 2026

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Reduce unnecessary string allocations in frequently-executed code paths by replacing inefficient string concatenation patterns with direct write!() calls.

Changes

  • Query result formatting (physical_plans/format/common.rs): Replace += &format!() with write!() to avoid intermediate String allocations in pruning statistics generation

  • Parser errors (parser/error.rs): Use write!() instead of += &format!() pattern

  • Optimizer trace (optimizer/pipeline/trace/trace.rs): Replace push_str(&format!()) with write!()/writeln!() throughout the trace report generation

Before:

blocks_pruning_description += &format!("range pruning: {} to {}", before, after);
summary.push_str(&format!("[{}] {}: {}\n", status, index, name));

After:

write!(blocks_pruning_description, "range pruning: {} to {}", before, after).unwrap();
writeln!(summary, "[{}] {}: {}", status, index, name).unwrap();

These paths are executed per-query, making allocation reduction meaningful at scale.

Continues the work from #19163.

Tests

  • No Test - Build and clippy verified locally

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

Replace inefficient string concatenation patterns:
- Use write!() instead of += &format!() in physical_plans/format/common.rs
- Use write!() instead of += &format!() in parser/error.rs
- Use write!()/writeln!() instead of push_str(&format!()) in optimizer trace

These patterns are executed per-query, making allocation reduction meaningful.
@sundy-li sundy-li changed the title perf: reduce string allocations in hot paths refactor(query): reduce string allocations in hot paths Jan 7, 2026
@github-actions github-actions bot added the pr-refactor this PR changes the code base without new features or bugfix label Jan 7, 2026
@sundy-li sundy-li requested a review from b41sh January 7, 2026 13:54
@sundy-li sundy-li merged commit 966c616 into databendlabs:main Jan 8, 2026
91 of 93 checks passed
@sundy-li sundy-li deleted the fix/reduce-allocations branch January 8, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-refactor this PR changes the code base without new features or bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants