diff --git a/rs/nns/governance/canbench/canbench_results.yml b/rs/nns/governance/canbench/canbench_results.yml index a8de4d0661d..9cd94b98d3f 100644 --- a/rs/nns/governance/canbench/canbench_results.yml +++ b/rs/nns/governance/canbench/canbench_results.yml @@ -1,55 +1,55 @@ benches: add_neuron_active_maximum: total: - instructions: 36177920 + instructions: 36176826 heap_increase: 1 stable_memory_increase: 0 scopes: {} add_neuron_active_typical: total: - instructions: 1835389 + instructions: 1835322 heap_increase: 0 stable_memory_increase: 0 scopes: {} add_neuron_inactive_maximum: total: - instructions: 96156666 + instructions: 96155572 heap_increase: 1 stable_memory_increase: 0 scopes: {} add_neuron_inactive_typical: total: - instructions: 7370994 + instructions: 7370927 heap_increase: 0 stable_memory_increase: 0 scopes: {} cascading_vote_all_heap: total: - instructions: 34432365 + instructions: 34422494 heap_increase: 0 stable_memory_increase: 128 scopes: {} cascading_vote_heap_neurons_stable_index: total: - instructions: 56567262 + instructions: 56557391 heap_increase: 0 stable_memory_increase: 128 scopes: {} cascading_vote_stable_everything: total: - instructions: 372102159 + instructions: 371631388 heap_increase: 0 stable_memory_increase: 128 scopes: {} cascading_vote_stable_neurons_with_heap_index: total: - instructions: 349917023 + instructions: 349446252 heap_increase: 0 stable_memory_increase: 128 scopes: {} centralized_following_all_stable: total: - instructions: 173910217 + instructions: 173749742 heap_increase: 0 stable_memory_increase: 128 scopes: {} @@ -61,7 +61,7 @@ benches: scopes: {} draw_maturity_from_neurons_fund_heap: total: - instructions: 7252619 + instructions: 7245419 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -73,16 +73,22 @@ benches: scopes: {} list_active_neurons_fund_neurons_heap: total: - instructions: 438096 + instructions: 440980 heap_increase: 0 stable_memory_increase: 0 scopes: {} list_active_neurons_fund_neurons_stable: total: - instructions: 10293308 + instructions: 2450275 heap_increase: 0 stable_memory_increase: 0 scopes: {} + list_neurons_heap: + total: + instructions: 3900688 + heap_increase: 9 + stable_memory_increase: 0 + scopes: {} list_neurons_ready_to_unstake_maturity_heap: total: instructions: 471240 @@ -91,10 +97,16 @@ benches: scopes: {} list_neurons_ready_to_unstake_maturity_stable: total: - instructions: 36937433 + instructions: 36937653 heap_increase: 0 stable_memory_increase: 0 scopes: {} + list_neurons_stable: + total: + instructions: 97867451 + heap_increase: 5 + stable_memory_increase: 0 + scopes: {} list_ready_to_spawn_neuron_ids_heap: total: instructions: 459353 @@ -103,19 +115,19 @@ benches: scopes: {} list_ready_to_spawn_neuron_ids_stable: total: - instructions: 36926134 + instructions: 36926354 heap_increase: 0 stable_memory_increase: 0 scopes: {} neuron_metrics_calculation_heap: total: - instructions: 536345 + instructions: 1077651 heap_increase: 0 stable_memory_increase: 0 scopes: {} neuron_metrics_calculation_stable: total: - instructions: 1841727 + instructions: 2476865 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -127,7 +139,7 @@ benches: scopes: {} single_vote_all_stable: total: - instructions: 2474981 + instructions: 2474974 heap_increase: 0 stable_memory_increase: 128 scopes: {} diff --git a/rs/nns/governance/src/governance/benches.rs b/rs/nns/governance/src/governance/benches.rs index 54458386752..e1ced18cfac 100644 --- a/rs/nns/governance/src/governance/benches.rs +++ b/rs/nns/governance/src/governance/benches.rs @@ -4,7 +4,8 @@ use crate::{ neuron_store::NeuronStore, pb::v1::{ neuron::Followees, proposal::Action, Ballot, BallotInfo, Governance as GovernanceProto, - KnownNeuron, Neuron as NeuronProto, ProposalData, Topic, Vote, VotingPowerEconomics, + KnownNeuron, ListNeurons, Neuron as NeuronProto, ProposalData, Topic, Vote, + VotingPowerEconomics, }, temporarily_disable_active_neurons_in_stable_memory, temporarily_disable_stable_memory_following_index, @@ -512,3 +513,58 @@ fn compute_ballots_for_new_proposal_with_stable_neurons() -> BenchResult { .expect("Failed!"); }) } + +fn list_neurons_benchmark() -> BenchResult { + let neurons = (0..100) + .map(|id| { + (id, { + let mut neuron: NeuronProto = make_neuron( + id, + PrincipalId::new_user_test_id(id), + 1_000_000_000, + hashmap! {}, // get the default followees + ) + .into_proto(&VotingPowerEconomics::DEFAULT, 123_456_789); + neuron.hot_keys = vec![PrincipalId::new_user_test_id(1)]; + neuron + }) + }) + .collect::>(); + + let governance_proto = GovernanceProto { + neurons, + ..GovernanceProto::default() + }; + + let governance = Governance::new( + governance_proto, + Box::new(MockEnvironment::new(Default::default(), 0)), + Box::new(StubIcpLedger {}), + Box::new(StubCMC {}), + ); + + let request = ListNeurons { + neuron_ids: vec![], + include_neurons_readable_by_caller: true, + include_empty_neurons_readable_by_caller: Some(false), + include_public_neurons_in_full_neurons: None, + }; + + bench_fn(|| { + governance.list_neurons(&request, PrincipalId::new_user_test_id(1)); + }) +} + +/// Benchmark list_neurons +#[bench(raw)] +fn list_neurons_stable() -> BenchResult { + let _f = temporarily_enable_active_neurons_in_stable_memory(); + list_neurons_benchmark() +} + +/// Benchmark list_neurons +#[bench(raw)] +fn list_neurons_heap() -> BenchResult { + let _f = temporarily_disable_active_neurons_in_stable_memory(); + list_neurons_benchmark() +} diff --git a/rs/nns/governance/src/neuron_store.rs b/rs/nns/governance/src/neuron_store.rs index ead85cb62fe..b5a5f9ea673 100644 --- a/rs/nns/governance/src/neuron_store.rs +++ b/rs/nns/governance/src/neuron_store.rs @@ -1292,7 +1292,7 @@ impl NeuronStore { caller: PrincipalId, ) -> Vec { let is_non_empty = |neuron_id: &NeuronId| { - self.with_neuron(neuron_id, |neuron| neuron.is_funded()) + self.with_neuron_sections(neuron_id, NeuronSections::NONE, |neuron| neuron.is_funded()) .unwrap_or(false) };