Skip to content

Commit 1f525da

Browse files
perf(MR): Look up SubnetIds from a BTreeSet instead of from a Vec (dfinity#3779)
This is a minor optimization that has SystemStateModifications::apply_changes() build a BTreeSet>SubnetId> instead of a Vec<SubnetId>, since the resulting collection is only ever used for looking up specific SubnetIds.
1 parent 3fd26f1 commit 1f525da

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

rs/replicated_state/src/canister_state/queues.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ impl CanisterQueues {
11241124
&mut self,
11251125
request: Request,
11261126
reject_context: RejectContext,
1127-
subnet_ids: &[PrincipalId],
1127+
subnet_ids: &BTreeSet<PrincipalId>,
11281128
) -> Result<(), StateError> {
11291129
assert!(
11301130
request.receiver == IC_00 || subnet_ids.contains(&request.receiver.get()),

rs/replicated_state/src/canister_state/queues/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2689,7 +2689,7 @@ fn test_reject_subnet_output_request() {
26892689

26902690
// Reject an output request without having enqueued it first.
26912691
queues
2692-
.reject_subnet_output_request(request, reject_context.clone(), &[])
2692+
.reject_subnet_output_request(request, reject_context.clone(), &BTreeSet::new())
26932693
.unwrap();
26942694

26952695
// There is now a reject response.

rs/replicated_state/src/canister_state/system_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ impl SystemState {
11521152
&mut self,
11531153
request: Request,
11541154
reject_context: RejectContext,
1155-
subnet_ids: &[PrincipalId],
1155+
subnet_ids: &BTreeSet<PrincipalId>,
11561156
) -> Result<(), StateError> {
11571157
assert_eq!(
11581158
request.sender, self.canister_id,

rs/system_api/src/sandbox_safe_system_state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl SystemStateModifications {
151151

152152
fn reject_subnet_message_routing(
153153
system_state: &mut SystemState,
154-
subnet_ids: &[PrincipalId],
154+
subnet_ids: &BTreeSet<PrincipalId>,
155155
msg: Request,
156156
err: ResolveDestinationError,
157157
logger: &ReplicaLogger,
@@ -178,7 +178,7 @@ impl SystemStateModifications {
178178

179179
fn reject_subnet_message_user_error(
180180
system_state: &mut SystemState,
181-
subnet_ids: &[PrincipalId],
181+
subnet_ids: &BTreeSet<PrincipalId>,
182182
msg: Request,
183183
err: UserError,
184184
logger: &ReplicaLogger,
@@ -367,7 +367,7 @@ impl SystemStateModifications {
367367
// Push outgoing messages.
368368
let mut callback_changes = BTreeMap::new();
369369
let nns_subnet_id = network_topology.nns_subnet_id;
370-
let subnet_ids: Vec<PrincipalId> =
370+
let subnet_ids: BTreeSet<PrincipalId> =
371371
network_topology.subnets.keys().map(|s| s.get()).collect();
372372
for mut msg in self.requests {
373373
if msg.receiver == IC_00 {

0 commit comments

Comments
 (0)