Skip to content

Commit 0598720

Browse files
committed
[ISSUE #1132]⚡️Optimize std String with Cheetah String🔥
1 parent ef76152 commit 0598720

File tree

59 files changed

+1294
-1304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1294
-1304
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ uuid = { version = "1.11.0", features = ["v4", # Lets you generate random UUIDs
8181

8282
futures = "0.3"
8383

84-
cheetah-string = { version = "0.1.0", features = ["serde", "bytes"] }
84+
cheetah-string = { git = "https://github.com/mxsm/cheetah-string.git", features = ["serde", "bytes"] }

rocketmq-broker/src/broker_runtime.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::sync::atomic::Ordering;
2121
use std::sync::Arc;
2222
use std::time::Duration;
2323

24+
use cheetah_string::CheetahString;
2425
use rocketmq_common::common::broker::broker_config::BrokerConfig;
2526
use rocketmq_common::common::config::TopicConfig;
2627
use rocketmq_common::common::config_manager::ConfigManager;
@@ -955,10 +956,10 @@ impl BrokerRuntime {
955956
.broker_cluster_name
956957
.clone();
957958
let broker_name = self.broker_config.broker_identity.broker_name.clone();
958-
let broker_addr = format!(
959+
let broker_addr = CheetahString::from_string(format!(
959960
"{}:{}",
960961
self.broker_config.broker_ip1, self.server_config.listen_port
961-
);
962+
));
962963
let broker_id = self.broker_config.broker_identity.broker_id;
963964
let weak = Arc::downgrade(&self.broker_out_api);
964965
self.broker_out_api
@@ -1074,10 +1075,10 @@ impl BrokerRuntimeInner {
10741075
.broker_cluster_name
10751076
.clone();
10761077
let broker_name = self.broker_config.broker_identity.broker_name.clone();
1077-
let broker_addr = format!(
1078+
let broker_addr = CheetahString::from_string(format!(
10781079
"{}:{}",
10791080
self.broker_config.broker_ip1, self.server_config.listen_port
1080-
);
1081+
));
10811082
let broker_id = self.broker_config.broker_identity.broker_id;
10821083
let weak = Arc::downgrade(&self.broker_out_api);
10831084
self.broker_out_api

rocketmq-broker/src/mqtrace/consume_message_context.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,36 @@
1717
use std::collections::HashMap;
1818
use std::sync::Arc;
1919

20+
use cheetah_string::CheetahString;
2021
use rocketmq_common::common::config::TopicConfig;
2122
use rocketmq_store::stats::stats_type::StatsType;
2223

2324
#[derive(Default)]
2425
pub struct ConsumeMessageContext {
25-
pub consumer_group: String,
26-
pub topic: String,
26+
pub consumer_group: CheetahString,
27+
pub topic: CheetahString,
2728
pub queue_id: Option<i32>,
28-
pub client_host: String,
29-
pub store_host: String,
29+
pub client_host: CheetahString,
30+
pub store_host: CheetahString,
3031
pub message_ids: HashMap<String, i64>,
3132
pub body_length: i32,
3233
pub success: bool,
33-
pub status: String,
34+
pub status: CheetahString,
3435
//mq_trace_context: Option<Box<dyn std::any::Any>>, // Replace with actual type
3536
pub topic_config: Arc<TopicConfig>,
3637

37-
pub account_auth_type: Option<String>,
38-
pub account_owner_parent: Option<String>,
39-
pub account_owner_self: Option<String>,
38+
pub account_auth_type: Option<CheetahString>,
39+
pub account_owner_parent: Option<CheetahString>,
40+
pub account_owner_self: Option<CheetahString>,
4041
pub rcv_msg_num: i32,
4142
pub rcv_msg_size: i32,
4243
pub rcv_stat: StatsType,
4344
pub commercial_rcv_msg_num: i32,
4445

45-
pub commercial_owner: Option<String>,
46+
pub commercial_owner: Option<CheetahString>,
4647
pub commercial_rcv_stats: StatsType,
4748
pub commercial_rcv_times: i32,
4849
pub commercial_rcv_size: i32,
4950

50-
pub namespace: String,
51+
pub namespace: CheetahString,
5152
}

rocketmq-broker/src/mqtrace/send_message_context.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,41 @@
1717
use std::any::Any;
1818
use std::collections::HashMap;
1919

20+
use cheetah_string::CheetahString;
2021
use rocketmq_common::common::message::message_enum::MessageType;
2122
use rocketmq_store::stats::stats_type::StatsType;
2223

2324
#[derive(Debug, Default)]
2425
pub struct SendMessageContext {
25-
pub namespace: String,
26-
pub producer_group: String,
27-
pub topic: String,
28-
pub msg_id: String,
29-
pub origin_msg_id: String,
26+
pub namespace: CheetahString,
27+
pub producer_group: CheetahString,
28+
pub topic: CheetahString,
29+
pub msg_id: CheetahString,
30+
pub origin_msg_id: CheetahString,
3031
pub queue_id: Option<i32>,
3132
pub queue_offset: Option<i64>,
32-
pub broker_addr: String,
33-
pub born_host: String,
33+
pub broker_addr: CheetahString,
34+
pub born_host: CheetahString,
3435
pub body_length: i32,
3536
pub code: i32,
36-
pub error_msg: String,
37-
pub msg_props: String,
37+
pub error_msg: CheetahString,
38+
pub msg_props: CheetahString,
3839
pub mq_trace_context: Option<Box<dyn Any + Send + 'static>>,
3940
pub ext_props: HashMap<String, String>,
40-
pub broker_region_id: String,
41-
pub msg_unique_key: String,
41+
pub broker_region_id: CheetahString,
42+
pub msg_unique_key: CheetahString,
4243
pub born_time_stamp: i64,
4344
pub request_time_stamp: i64,
4445
pub msg_type: MessageType,
4546
pub is_success: bool,
46-
pub account_auth_type: String,
47-
pub account_owner_parent: String,
48-
pub account_owner_self: String,
47+
pub account_auth_type: CheetahString,
48+
pub account_owner_parent: CheetahString,
49+
pub account_owner_self: CheetahString,
4950
pub send_msg_num: i32,
5051
pub send_msg_size: i32,
5152
pub send_stat: StatsType,
5253
pub commercial_send_msg_num: i32,
53-
pub commercial_owner: String,
54+
pub commercial_owner: CheetahString,
5455
pub commercial_send_stats: StatsType,
5556
pub commercial_send_size: i32,
5657
pub commercial_send_times: i32,
@@ -60,19 +61,19 @@ impl SendMessageContext {
6061
Self::default()
6162
}
6263

63-
pub fn topic(&mut self, topic: String) {
64+
pub fn topic(&mut self, topic: CheetahString) {
6465
self.topic = topic;
6566
}
6667

6768
pub fn body_length(&mut self, body_length: i32) {
6869
self.body_length = body_length;
6970
}
7071

71-
pub fn msg_props(&mut self, msg_props: String) {
72+
pub fn msg_props(&mut self, msg_props: CheetahString) {
7273
self.msg_props = msg_props;
7374
}
7475

75-
pub fn broker_addr(&mut self, broker_addr: String) {
76+
pub fn broker_addr(&mut self, broker_addr: CheetahString) {
7677
self.broker_addr = broker_addr;
7778
}
7879

@@ -84,15 +85,15 @@ impl SendMessageContext {
8485
self.queue_offset = Some(queue_offset);
8586
}
8687

87-
pub fn born_host(&mut self, born_host: String) {
88+
pub fn born_host(&mut self, born_host: CheetahString) {
8889
self.born_host = born_host;
8990
}
9091

91-
pub fn broker_region_id(&mut self, broker_region_id: String) {
92+
pub fn broker_region_id(&mut self, broker_region_id: CheetahString) {
9293
self.broker_region_id = broker_region_id;
9394
}
9495

95-
pub fn msg_unique_key(&mut self, msg_unique_key: String) {
96+
pub fn msg_unique_key(&mut self, msg_unique_key: CheetahString) {
9697
self.msg_unique_key = msg_unique_key;
9798
}
9899

@@ -112,15 +113,15 @@ impl SendMessageContext {
112113
self.is_success = is_success;
113114
}
114115

115-
pub fn account_auth_type(&mut self, account_auth_type: String) {
116+
pub fn account_auth_type(&mut self, account_auth_type: CheetahString) {
116117
self.account_auth_type = account_auth_type;
117118
}
118119

119-
pub fn account_owner_parent(&mut self, account_owner_parent: String) {
120+
pub fn account_owner_parent(&mut self, account_owner_parent: CheetahString) {
120121
self.account_owner_parent = account_owner_parent;
121122
}
122123

123-
pub fn account_owner_self(&mut self, account_owner_self: String) {
124+
pub fn account_owner_self(&mut self, account_owner_self: CheetahString) {
124125
self.account_owner_self = account_owner_self;
125126
}
126127

@@ -140,7 +141,7 @@ impl SendMessageContext {
140141
self.commercial_send_msg_num = commercial_send_msg_num;
141142
}
142143

143-
pub fn commercial_owner(&mut self, commercial_owner: String) {
144+
pub fn commercial_owner(&mut self, commercial_owner: CheetahString) {
144145
self.commercial_owner = commercial_owner;
145146
}
146147

rocketmq-broker/src/out_api/broker_outer_api.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl BrokerOuterAPI {
103103

104104
fn create_request(broker_name: CheetahString, topic_config: TopicConfig) -> RemotingCommand {
105105
let request_header =
106-
RegisterTopicRequestHeader::new(topic_config.topic_name.as_ref().unwrap());
106+
RegisterTopicRequestHeader::new(topic_config.topic_name.as_ref().cloned().unwrap());
107107
let queue_data = QueueData::new(
108108
broker_name.clone(),
109109
topic_config.read_queue_nums,
@@ -148,10 +148,10 @@ impl BrokerOuterAPI {
148148
pub async fn register_broker_all(
149149
&self,
150150
cluster_name: CheetahString,
151-
broker_addr: String,
151+
broker_addr: CheetahString,
152152
broker_name: CheetahString,
153153
broker_id: u64,
154-
ha_server_addr: String,
154+
ha_server_addr: CheetahString,
155155
topic_config_wrapper: TopicConfigAndMappingSerializeWrapper,
156156
filter_server_list: Vec<String>,
157157
oneway: bool,
@@ -273,9 +273,16 @@ impl BrokerOuterAPI {
273273
response.decode_command_custom_header::<RegisterBrokerResponseHeader>();
274274
let mut result = RegisterBrokerResult::default();
275275
if let Some(header) = register_broker_result {
276-
result.ha_server_addr =
277-
header.ha_server_addr.clone().unwrap_or("".to_string());
278-
result.master_addr = header.master_addr.clone().unwrap_or("".to_string());
276+
result.ha_server_addr = header
277+
.ha_server_addr
278+
.clone()
279+
.unwrap_or(CheetahString::empty())
280+
.to_string();
281+
result.master_addr = header
282+
.master_addr
283+
.clone()
284+
.unwrap_or(CheetahString::empty())
285+
.to_string();
279286
}
280287
if let Some(body) = response.body() {
281288
result.kv_table = SerdeJsonUtils::decode::<KVTable>(body.as_ref()).unwrap();
@@ -353,7 +360,11 @@ impl BrokerOuterAPI {
353360
} else {
354361
Err(BrokerError::MQBrokerError(
355362
response.code(),
356-
response.remark().cloned().unwrap_or("".to_string()),
363+
response
364+
.remark()
365+
.cloned()
366+
.unwrap_or(CheetahString::empty())
367+
.to_json(),
357368
"".to_string(),
358369
))
359370
}
@@ -384,7 +395,11 @@ impl BrokerOuterAPI {
384395
} else {
385396
Err(BrokerError::MQBrokerError(
386397
response.code(),
387-
response.remark().cloned().unwrap_or("".to_string()),
398+
response
399+
.remark()
400+
.cloned()
401+
.unwrap_or(CheetahString::empty())
402+
.to_string(),
388403
"".to_string(),
389404
))
390405
}

rocketmq-broker/src/processor/admin_broker_processor/consumer_request_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl ConsumerRequestHandler {
117117
.consumer_offset_manager
118118
.which_topic_by_consumer(request_header.get_consumer_group());
119119
} else {
120-
topics.insert(request_header.get_topic().clone());
120+
topics.insert(request_header.get_topic().to_string());
121121
}
122122
for topic in topics.iter() {
123123
let topic_config = self.inner.topic_config_manager.select_topic_config(topic);

rocketmq-broker/src/processor/admin_broker_processor/topic_request_handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use std::collections::HashMap;
1919
use std::collections::HashSet;
2020

21+
use cheetah_string::CheetahString;
2122
use rocketmq_common::common::attribute::attribute_parser::AttributeParser;
2223
use rocketmq_common::common::attribute::topic_message_type::TopicMessageType;
2324
use rocketmq_common::common::config::TopicConfig;
@@ -109,7 +110,7 @@ impl TopicRequestHandler {
109110
request_header
110111
.attributes
111112
.clone()
112-
.unwrap_or("".to_string())
113+
.unwrap_or(CheetahString::empty())
113114
.as_str(),
114115
) {
115116
Ok(value) => value,

rocketmq-broker/src/processor/client_manage_processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ where
109109

110110
let client_channel_info = ClientChannelInfo::new(
111111
channel.clone(),
112-
request_header.client_id.clone(),
112+
request_header.client_id.to_string(),
113113
request.language(),
114114
request.version(),
115115
);

rocketmq-broker/src/processor/consumer_manage_processor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ where
331331
.topic_queue_mapping_info
332332
.bname
333333
.as_ref()
334-
.unwrap_or(&"".to_string())
334+
.cloned()
335+
.unwrap_or_default()
335336
),
336337
));
337338
}
@@ -354,8 +355,7 @@ where
354355
break;
355356
}
356357
} else {
357-
request_header
358-
.set_broker_name(mapping_item.bname.clone().unwrap_or("".to_string()));
358+
request_header.set_broker_name(mapping_item.bname.clone().unwrap_or_default());
359359
request_header.queue_id = mapping_item.queue_id;
360360
request_header.set_lo(Some(false));
361361
request_header.set_zero_if_not_found = Some(true);

0 commit comments

Comments
 (0)