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 22, 2025
1 parent 5f5a15d commit 650e118
Show file tree
Hide file tree
Showing 11 changed files with 530 additions and 688 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
32 changes: 16 additions & 16 deletions rs/nns/governance/canbench/canbench_results.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
benches:
add_neuron_active_maximum:
total:
instructions: 42749561
instructions: 42753167
heap_increase: 1
stable_memory_increase: 0
scopes: {}
add_neuron_active_typical:
total:
instructions: 2170531
instructions: 2171029
heap_increase: 0
stable_memory_increase: 0
scopes: {}
add_neuron_inactive_maximum:
total:
instructions: 112621399
instructions: 112624752
heap_increase: 1
stable_memory_increase: 0
scopes: {}
add_neuron_inactive_typical:
total:
instructions: 8497168
instructions: 8497413
heap_increase: 0
stable_memory_increase: 0
scopes: {}
cascading_vote_all_heap:
total:
instructions: 34979056
instructions: 35100222
heap_increase: 0
stable_memory_increase: 128
scopes: {}
cascading_vote_heap_neurons_stable_index:
total:
instructions: 61114095
instructions: 61235261
heap_increase: 0
stable_memory_increase: 128
scopes: {}
cascading_vote_stable_everything:
total:
instructions: 188616886
instructions: 188615038
heap_increase: 0
stable_memory_increase: 128
scopes: {}
cascading_vote_stable_neurons_with_heap_index:
total:
instructions: 162348451
instructions: 162346603
heap_increase: 0
stable_memory_increase: 128
scopes: {}
centralized_following_all_stable:
total:
instructions: 78267527
instructions: 78266619
heap_increase: 0
stable_memory_increase: 128
scopes: {}
compute_ballots_for_new_proposal_with_stable_neurons:
total:
instructions: 2222211
instructions: 2169168
heap_increase: 0
stable_memory_increase: 0
scopes: {}
draw_maturity_from_neurons_fund_heap:
total:
instructions: 7584430
instructions: 7669430
heap_increase: 0
stable_memory_increase: 0
scopes: {}
Expand Down Expand Up @@ -109,7 +109,7 @@ benches:
scopes: {}
list_proposals:
total:
instructions: 6477736
instructions: 130094
heap_increase: 0
stable_memory_increase: 0
scopes: {}
Expand All @@ -127,13 +127,13 @@ benches:
scopes: {}
neuron_data_validation_heap:
total:
instructions: 406848584
instructions: 406935048
heap_increase: 0
stable_memory_increase: 0
scopes: {}
neuron_data_validation_stable:
total:
instructions: 362648972
instructions: 362718034
heap_increase: 0
stable_memory_increase: 0
scopes: {}
Expand All @@ -145,7 +145,7 @@ benches:
scopes: {}
neuron_metrics_calculation_stable:
total:
instructions: 3021895
instructions: 3027095
heap_increase: 0
stable_memory_increase: 0
scopes: {}
Expand All @@ -157,7 +157,7 @@ benches:
scopes: {}
single_vote_all_stable:
total:
instructions: 2803117
instructions: 2803114
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 @@ -778,9 +778,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 @@ -796,17 +794,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 @@ -888,7 +882,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 650e118

Please sign in to comment.