Skip to content

Commit

Permalink
perf: optimize memory allocation on building object path (#18465)
Browse files Browse the repository at this point in the history
Signed-off-by: MrCroxx <[email protected]>
  • Loading branch information
MrCroxx authored Sep 11, 2024
1 parent 00150a3 commit 084bc6d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/storage/hummock_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub const FIRST_VERSION_ID: HummockVersionId = HummockVersionId(1);
pub const SPLIT_TABLE_COMPACTION_GROUP_ID_HEAD: u64 = 1u64 << 56;
pub const SINGLE_TABLE_COMPACTION_GROUP_ID_HEAD: u64 = 2u64 << 56;
pub const OBJECT_SUFFIX: &str = "data";
pub const HUMMOCK_SSTABLE_OBJECT_ID_MAX_DECIMAL_LENGTH: usize = 20;

#[macro_export]
/// This is wrapper for `info` log.
Expand Down Expand Up @@ -359,3 +360,14 @@ impl EpochWithGap {
self.0 & EPOCH_SPILL_TIME_MASK
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_object_id_decimal_max_length() {
let len = HummockSstableObjectId::MAX.to_string().len();
assert_eq!(len, HUMMOCK_SSTABLE_OBJECT_ID_MAX_DECIMAL_LENGTH)
}
}
23 changes: 18 additions & 5 deletions src/storage/src/hummock/sstable_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ use foyer::{
use futures::{future, StreamExt};
use itertools::Itertools;
use risingwave_hummock_sdk::sstable_info::SstableInfo;
use risingwave_hummock_sdk::{HummockSstableObjectId, OBJECT_SUFFIX};
use risingwave_hummock_sdk::{
HummockSstableObjectId, HUMMOCK_SSTABLE_OBJECT_ID_MAX_DECIMAL_LENGTH, OBJECT_SUFFIX,
};
use risingwave_hummock_trace::TracedCachePolicy;
use risingwave_object_store::object::{
ObjectError, ObjectMetadataIter, ObjectResult, ObjectStoreRef, ObjectStreamingUploader,
Expand Down Expand Up @@ -519,10 +521,21 @@ impl SstableStore {
let obj_prefix = self
.store
.get_object_prefix(object_id, self.use_new_object_prefix_strategy);
format!(
"{}/{}{}.{}",
self.path, obj_prefix, object_id, OBJECT_SUFFIX
)
let mut path = String::with_capacity(
self.path.len()
+ "/".len()
+ obj_prefix.len()
+ HUMMOCK_SSTABLE_OBJECT_ID_MAX_DECIMAL_LENGTH
+ ".".len()
+ OBJECT_SUFFIX.len(),
);
path.push_str(&self.path);
path.push('/');
path.push_str(&obj_prefix);
path.push_str(&object_id.to_string());
path.push('.');
path.push_str(OBJECT_SUFFIX);
path
}

pub fn get_object_id_from_path(path: &str) -> HummockSstableObjectId {
Expand Down

0 comments on commit 084bc6d

Please sign in to comment.