This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Optimize offchain worker memory usage a bit. #11454
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eebba96
add missing events to elections fallback
kianenigma dfec177
Merge branch 'master' of github.com:paritytech/substrate
kianenigma e549c94
Merged
kianenigma faac029
Merge branch 'master' of github.com:paritytech/substrate into kiz-ocw…
kianenigma 152d6b3
add some logs and stuff
kianenigma 8df1b06
master.into()
kianenigma c330bdb
undo a bunch of things
kianenigma 55ed210
undo lock file
kianenigma 3055e77
remove unused err
kianenigma 89c7e4f
fix build
kianenigma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,18 +120,17 @@ impl<AccountId> StakedAssignment<AccountId> { | |
AccountId: IdentifierT, | ||
{ | ||
let stake = self.total(); | ||
let distribution = self | ||
.distribution | ||
.into_iter() | ||
.filter_map(|(target, w)| { | ||
let per_thing = P::from_rational(w, stake); | ||
if per_thing == Bounded::min_value() { | ||
None | ||
} else { | ||
Some((target, per_thing)) | ||
} | ||
}) | ||
.collect::<Vec<(AccountId, P)>>(); | ||
// most likely, the size of the staked assignment and normal assignments will be the same, | ||
// so we pre-allocate it to prevent a sudden 2x allocation. `filter_map` starts with a size | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the context about filter map makes less sense if you dont know the diff. |
||
// of 0 by default. | ||
// https://www.reddit.com/r/rust/comments/3spfh1/does_collect_allocate_more_than_once_while/ | ||
let mut distribution = Vec::<(AccountId, P)>::with_capacity(self.distribution.len()); | ||
self.distribution.into_iter().for_each(|(target, w)| { | ||
let per_thing = P::from_rational(w, stake); | ||
if per_thing != Bounded::min_value() { | ||
distribution.push((target, per_thing)); | ||
} | ||
}); | ||
|
||
Assignment { who: self.who, distribution } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are those
clone
s necessary? Can't we change theprepare_election_result_with_snapshot
to take&[T]
instead of aVec<T>
for those? It doesn't seem to actually need those owned from what I can see?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the production code
prepare_election_result_with_snapshot
is the last place that we use these values so IMO it is cleaner to consume everything. Clones are only needed in tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, that's fine then.