This is an automated email from the ASF dual-hosted git repository.
yihua pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hudi-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 36ec34dd perf(core): sort hfile entries by reference instead of
cloning them (#894)
36ec34dd is described below
commit 36ec34dd58e12ae5bfc99044a80a2f1bbf68eb4a
Author: Y Ethan Guo <[email protected]>
AuthorDate: Thu Oct 29 21:00:41 2026 -0700
perf(core): sort hfile entries by reference instead of cloning them (#894)
closes #893
---
crates/core/src/hfile/writer.rs | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/crates/core/src/hfile/writer.rs b/crates/core/src/hfile/writer.rs
index 5dcaafab..0136a78d 100644
--- a/crates/core/src/hfile/writer.rs
+++ b/crates/core/src/hfile/writer.rs
@@ -40,7 +40,7 @@ impl HFileWriter {
entries: &[(String, Vec<u8>)],
mut file_info: BTreeMap<String, Vec<u8>>,
) -> Result<Vec<u8>> {
- let mut entries = entries.to_vec();
+ let mut entries: Vec<&(String, Vec<u8>)> = entries.iter().collect();
entries.sort_by(|left, right| left.0.cmp(&right.0));
let first_key = entries
@@ -54,7 +54,14 @@ impl HFileWriter {
.transpose()?
.unwrap_or_default();
- let mut data = Vec::new();
+ // Per entry: two i32 lengths, the structured key (content + 12 bytes
of
+ // framing), the value and a trailing byte.
+ let mut data = Vec::with_capacity(
+ entries
+ .iter()
+ .map(|(key, value)| key.len() + value.len() + 21)
+ .sum(),
+ );
for (key, value) in &entries {
let key = structured_key(key)?;
let key_len = i32::try_from(key.len())