Skip to content

Commit

Permalink
Avoid cloning large fields when listing proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonz-dfinity committed Jan 17, 2025
1 parent caf7fdd commit 6fbc513
Show file tree
Hide file tree
Showing 11 changed files with 533 additions and 691 deletions.
27 changes: 2 additions & 25 deletions rs/nns/governance/api/src/ic_nns_governance.pb.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1987,61 +1987,41 @@ pub struct WaitForQuietState {
/// This is a view of the ProposalData returned by API queries and is NOT used
/// for storage. The ballots are restricted to those of the caller's neurons and
/// additionally it has the computed fields, topic, status, and reward_status.
#[derive(candid::CandidType, candid::Deserialize, serde::Serialize, comparable::Comparable)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(candid::CandidType, candid::Deserialize, serde::Serialize, Clone, Debug, PartialEq)]
pub struct ProposalInfo {
/// The unique id for this proposal.
#[prost(message, optional, tag = "1")]
pub id: Option<::ic_nns_common::pb::v1::ProposalId>,
/// The ID of the neuron that made this proposal.
#[prost(message, optional, tag = "2")]
pub proposer: Option<NeuronId>,
/// The amount of ICP in E8s to be charged to the proposer if the proposal is
/// rejected.
#[prost(uint64, tag = "3")]
pub reject_cost_e8s: u64,
/// The proposal originally submitted.
#[prost(message, optional, tag = "4")]
pub proposal: Option<Proposal>,
/// The timestamp, in seconds from the Unix epoch, when this proposal was made.
#[prost(uint64, tag = "5")]
pub proposal_timestamp_seconds: u64,
/// See \[ProposalData::ballots\].
#[prost(map = "fixed64, message", tag = "6")]
pub ballots: ::std::collections::HashMap<u64, Ballot>,
/// See \[ProposalData::latest_tally\].
#[prost(message, optional, tag = "7")]
pub latest_tally: Option<Tally>,
/// See \[ProposalData::decided_timestamp_seconds\].
#[prost(uint64, tag = "8")]
pub decided_timestamp_seconds: u64,
/// See \[ProposalData::executed_timestamp_seconds\].
#[prost(uint64, tag = "12")]
pub executed_timestamp_seconds: u64,
/// See \[ProposalData::failed_timestamp_seconds\].
#[prost(uint64, tag = "13")]
pub failed_timestamp_seconds: u64,
/// See \[ProposalData::failure_reason\].
#[prost(message, optional, tag = "18")]
pub failure_reason: Option<GovernanceError>,
/// See \[ProposalData::reward_event_round\].
#[prost(uint64, tag = "14")]
pub reward_event_round: u64,
/// Derived - see \[Topic\] for more information
#[prost(enumeration = "Topic", tag = "15")]
pub topic: i32,
/// Derived - see \[ProposalStatus\] for more information
#[prost(enumeration = "ProposalStatus", tag = "16")]
pub status: i32,
/// Derived - see \[ProposalRewardStatus\] for more information
#[prost(enumeration = "ProposalRewardStatus", tag = "17")]
pub reward_status: i32,
#[prost(uint64, optional, tag = "19")]
pub deadline_timestamp_seconds: Option<u64>,
#[prost(message, optional, tag = "20")]
pub derived_proposal_information: Option<DerivedProposalInformation>,
#[prost(uint64, optional, tag = "21")]
pub total_potential_voting_power: ::core::option::Option<u64>,
}

Expand Down Expand Up @@ -3308,11 +3288,8 @@ pub struct ListProposalInfo {
#[prost(bool, optional, tag = "7")]
pub omit_large_fields: Option<bool>,
}
#[derive(candid::CandidType, candid::Deserialize, serde::Serialize, comparable::Comparable)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(candid::CandidType, candid::Deserialize, serde::Serialize, Clone, Debug, PartialEq)]
pub struct ListProposalInfoResponse {
#[prost(message, repeated, tag = "1")]
pub proposal_info: Vec<ProposalInfo>,
}
/// A request to list neurons. The "requested list", i.e., the list of
Expand Down
38 changes: 19 additions & 19 deletions rs/nns/governance/canbench/canbench_results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,55 @@ benches:
scopes: {}
add_neuron_inactive_maximum:
total:
instructions: 112785960
instructions: 112785713
heap_increase: 1
stable_memory_increase: 0
scopes: {}
add_neuron_inactive_typical:
total:
instructions: 8512855
instructions: 8512608
heap_increase: 0
stable_memory_increase: 0
scopes: {}
cascading_vote_all_heap:
total:
instructions: 35664264
instructions: 35665372
heap_increase: 0
stable_memory_increase: 128
scopes: {}
cascading_vote_heap_neurons_stable_index:
total:
instructions: 61826892
instructions: 61828000
heap_increase: 0
stable_memory_increase: 128
scopes: {}
cascading_vote_stable_everything:
total:
instructions: 189053935
instructions: 189053947
heap_increase: 0
stable_memory_increase: 128
scopes: {}
cascading_vote_stable_neurons_with_heap_index:
total:
instructions: 162757911
instructions: 162757923
heap_increase: 0
stable_memory_increase: 128
scopes: {}
centralized_following_all_stable:
total:
instructions: 78476198
instructions: 78476210
heap_increase: 0
stable_memory_increase: 128
scopes: {}
compute_ballots_for_new_proposal_with_stable_neurons:
total:
instructions: 1974268
instructions: 2027111
heap_increase: 0
stable_memory_increase: 0
scopes: {}
draw_maturity_from_neurons_fund_heap:
total:
instructions: 7650330
instructions: 7651130
heap_increase: 0
stable_memory_increase: 0
scopes: {}
Expand All @@ -73,13 +73,13 @@ benches:
scopes: {}
list_active_neurons_fund_neurons_heap:
total:
instructions: 432473
instructions: 435473
heap_increase: 0
stable_memory_increase: 0
scopes: {}
list_active_neurons_fund_neurons_stable:
total:
instructions: 2751735
instructions: 2754735
heap_increase: 0
stable_memory_increase: 0
scopes: {}
Expand All @@ -91,13 +91,13 @@ benches:
scopes: {}
list_neurons_ready_to_unstake_maturity_heap:
total:
instructions: 158253
instructions: 158257
heap_increase: 0
stable_memory_increase: 0
scopes: {}
list_neurons_ready_to_unstake_maturity_stable:
total:
instructions: 41329746
instructions: 41329753
heap_increase: 0
stable_memory_increase: 0
scopes: {}
Expand All @@ -109,7 +109,7 @@ benches:
scopes: {}
list_proposals:
total:
instructions: 6478119
instructions: 130274
heap_increase: 0
stable_memory_increase: 0
scopes: {}
Expand All @@ -127,25 +127,25 @@ benches:
scopes: {}
neuron_data_validation_heap:
total:
instructions: 408061813
instructions: 408061806
heap_increase: 0
stable_memory_increase: 0
scopes: {}
neuron_data_validation_stable:
total:
instructions: 363763701
instructions: 363763694
heap_increase: 0
stable_memory_increase: 0
scopes: {}
neuron_metrics_calculation_heap:
total:
instructions: 969848
instructions: 969248
heap_increase: 0
stable_memory_increase: 0
scopes: {}
neuron_metrics_calculation_stable:
total:
instructions: 2494760
instructions: 2494360
heap_increase: 0
stable_memory_increase: 0
scopes: {}
Expand All @@ -157,7 +157,7 @@ benches:
scopes: {}
single_vote_all_stable:
total:
instructions: 2804281
instructions: 2804293
heap_increase: 0
stable_memory_increase: 128
scopes: {}
Expand Down
17 changes: 7 additions & 10 deletions rs/nns/governance/canister/canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,7 @@ fn get_neuron_info_by_id_or_subaccount(
#[query]
fn get_proposal_info(id: ProposalId) -> Option<ProposalInfo> {
debug_log("get_proposal_info");
governance()
.get_proposal_info(&caller(), id)
.map(ProposalInfo::from)
GOVERNANCE.with_borrow(|governance| governance.get_proposal_info(&caller(), id))
}

#[query]
Expand All @@ -800,17 +798,13 @@ fn get_neurons_fund_audit_info(
#[query]
fn get_pending_proposals() -> Vec<ProposalInfo> {
debug_log("get_pending_proposals");
governance()
.get_pending_proposals(&caller())
.into_iter()
.map(ProposalInfo::from)
.collect()
GOVERNANCE.with_borrow(|governance| governance.get_pending_proposals(&caller()))
}

#[query]
fn list_proposals(req: ListProposalInfo) -> ListProposalInfoResponse {
debug_log("list_proposals");
governance().list_proposals(&caller(), &(req.into())).into()
GOVERNANCE.with_borrow(|governance| governance.list_proposals(&caller(), &req.into()))
}

#[query]
Expand Down Expand Up @@ -892,7 +886,10 @@ fn get_latest_reward_event() -> RewardEvent {
#[query]
fn get_neuron_ids() -> Vec<NeuronId> {
debug_log("get_neuron_ids");
let votable = governance().get_neuron_ids_by_principal(&caller());
let votable = governance()
.get_neuron_ids_by_principal(&caller())
.into_iter()
.collect();

governance()
.get_managed_neuron_ids_for(votable)
Expand Down
62 changes: 0 additions & 62 deletions rs/nns/governance/proto/ic_nns_governance/pb/v1/governance.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1780,64 +1780,6 @@ message WaitForQuietState {
uint64 current_deadline_timestamp_seconds = 1;
}

// This is a view of the ProposalData returned by API queries and is NOT used
// for storage. The ballots are restricted to those of the caller's neurons and
// additionally it has the computed fields, topic, status, and reward_status.
message ProposalInfo {
// The unique id for this proposal.
ic_nns_common.pb.v1.ProposalId id = 1;

// The ID of the neuron that made this proposal.
ic_nns_common.pb.v1.NeuronId proposer = 2;

// The amount of ICP in E8s to be charged to the proposer if the proposal is
// rejected.
uint64 reject_cost_e8s = 3;

// The proposal originally submitted.
Proposal proposal = 4;

// The timestamp, in seconds from the Unix epoch, when this proposal was made.
uint64 proposal_timestamp_seconds = 5;

// See [ProposalData::ballots].
map<fixed64, Ballot> ballots = 6;

// See [ProposalData::latest_tally].
Tally latest_tally = 7;

// See [ProposalData::decided_timestamp_seconds].
uint64 decided_timestamp_seconds = 8;

// See [ProposalData::executed_timestamp_seconds].
uint64 executed_timestamp_seconds = 12;

// See [ProposalData::failed_timestamp_seconds].
uint64 failed_timestamp_seconds = 13;

// See [ProposalData::failure_reason].
GovernanceError failure_reason = 18;

// See [ProposalData::reward_event_round].
uint64 reward_event_round = 14;

// Derived - see [Topic] for more information
Topic topic = 15;

// Derived - see [ProposalStatus] for more information
ProposalStatus status = 16;

// Derived - see [ProposalRewardStatus] for more information
ProposalRewardStatus reward_status = 17;

optional uint64 deadline_timestamp_seconds = 19;

DerivedProposalInformation derived_proposal_information = 20;

// See [ProposalData::total_potential_voting_power].
optional uint64 total_potential_voting_power = 21;
}

// Network economics contains the parameters for several operations related
// to the economy of the network. When submitting a NetworkEconomics proposal
// default values (0) are considered unchanged, so a valid proposal only needs
Expand Down Expand Up @@ -2630,10 +2572,6 @@ message ListProposalInfo {
optional bool omit_large_fields = 7;
}

message ListProposalInfoResponse {
repeated ProposalInfo proposal_info = 1;
}

// A request to list neurons. The "requested list", i.e., the list of
// neuron IDs to retrieve information about, is the union of the list
// of neurons listed in `neuron_ids` and, if `caller_neurons` is true,
Expand Down
Loading

0 comments on commit 6fbc513

Please sign in to comment.