Skip to content

Conversation

Copy link

Copilot AI commented Dec 26, 2025

Identified and eliminated unnecessary allocations in frequently-executed code paths through targeted refactoring of string operations and collection initialization.

Changes

  • Query result formatting (executor/format.rs): Replaced += &format!() with direct write!() calls to avoid intermediate String allocations in pruning statistics generation

  • Metadata key operations (kv_pb_api/mod.rs): Pre-allocate result vectors with known capacity instead of growing incrementally during chunked key processing

  • Key construction (key_builder.rs): Write numeric values directly to byte buffer via std::io::Write instead of allocating temporary strings

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

Before:

blocks_pruning_description += &format!("range pruning: {} to {}", before, after);
let mut res = vec![];  // grows via multiple extends
self.push_raw(&format!("{}", n))

After:

write!(blocks_pruning_description, "range pruning: {} to {}", before, after).unwrap();
let mut res = Vec::with_capacity(total_keys);
write!(self.buf, "{}", n).unwrap();

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

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --check-cfg cfg(docsrs,test) --check-cfg cfg(feature, values()) n-li�� n-linux-gnu/lib/debuginfo=2 7792/build_script_build-6014bd6bab5c7792 n-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/bin/rust-lld n-linux-gnu/lib//home/REDACTED/.rustup/toolchains/nightly-2025-12-11-x86_64-REDACTED-linux-gnu/bin/rustc n-linux-gnu/lib/--crate-name n-linux-gnu/lib/display_more n-linux-gnu/lib/--edition=2021 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Identify and suggest improvements to slow or inefficient code


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


This change is Reviewable

@github-actions
Copy link
Contributor

github-actions bot commented Dec 26, 2025

At least one test kind must be checked in the PR description.
@Copilot please update it 🙏.

@github-actions
Copy link
Contributor

Pull request description must contain CLA like the following:

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

## Summary

Summary about this PR

- Close #issue

@github-actions
Copy link
Contributor

github-actions bot commented Dec 26, 2025

At least one type of change must be checked in the PR description.
@Copilot please update it 🙏.

Copilot AI and others added 3 commits December 26, 2025 03:07
- Replace += &format!() with write!() macro in format.rs to avoid unnecessary allocations
- Replace += with push_str() for string literals in parser/error.rs
- Add Vec::with_capacity in kv_pb_api for pre-allocated vectors
- Optimize u64 formatting in key_builder.rs to write directly to buffer

Co-authored-by: sundy-li <[email protected]>
Move std::io::Write import inside the function to avoid trait conflicts

Co-authored-by: sundy-li <[email protected]>
Improve code organization by placing imports at the module level

Co-authored-by: sundy-li <[email protected]>
Copilot AI changed the title [WIP] Identify and suggest improvements to slow code Optimize hot path allocations in query formatting and metadata operations Dec 26, 2025
Copilot AI requested a review from sundy-li December 26, 2025 03:21
@sundy-li sundy-li changed the title Optimize hot path allocations in query formatting and metadata operations chore(query): Optimize hot path allocations in query formatting and metadata operations Dec 26, 2025
@github-actions github-actions bot added the pr-chore this PR only has small changes that no need to record, like coding styles. label Dec 26, 2025
@github-actions
Copy link
Contributor

This pull request's title is not fulfill the requirements. @Copilot please update it 🙏.

Valid format:

fix(query): fix group by string bug
  ^         ^---------------------^
  |         |
  |         +-> Summary in present tense.
  |
  +-------> Type: rfc, feat, fix, refactor, ci, docs, chore

Valid types:

  • rfc: this PR proposes a new RFC
  • feat: this PR introduces a new feature to the codebase
  • fix: this PR patches a bug in codebase
  • refactor: this PR changes the code base without new features or bugfix
  • ci: this PR changes build/testing/ci steps
  • docs: this PR changes the documents or websites
  • chore: this PR only has small changes that no need to record

1 similar comment
@github-actions
Copy link
Contributor

This pull request's title is not fulfill the requirements. @Copilot please update it 🙏.

Valid format:

fix(query): fix group by string bug
  ^         ^---------------------^
  |         |
  |         +-> Summary in present tense.
  |
  +-------> Type: rfc, feat, fix, refactor, ci, docs, chore

Valid types:

  • rfc: this PR proposes a new RFC
  • feat: this PR introduces a new feature to the codebase
  • fix: this PR patches a bug in codebase
  • refactor: this PR changes the code base without new features or bugfix
  • ci: this PR changes build/testing/ci steps
  • docs: this PR changes the documents or websites
  • chore: this PR only has small changes that no need to record

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-chore this PR only has small changes that no need to record, like coding styles.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants