Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process_inherent_data: use an in memory overlay to minimize reads and writes to storage #3644

Closed
wants to merge 50 commits into from

Conversation

sandreim
Copy link
Contributor

@sandreim sandreim commented Mar 11, 2024

Changes on top of #3479

Introduce a genericStorageMapOverlay and use it to efficiently mutate PendingAvailability storage in memory. Early in process_inherent_data we create this overlay and only write back what was changed before returning from the function.

Runtime APIs must still access the storage directly.

This changeset doesn't attempt to solve any logic issues that have been identified in the review of #3479, but it does try to help with allowing to change values while iterating the in-memory map, currently at the cost of an extra clone.

@sandreim sandreim added the R0-silent Changes should not be mentioned in any release notes label Mar 11, 2024
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
@sandreim
Copy link
Contributor Author

bot bench polkadot-pallet --runtime=westend --pallet=runtime_parachains::paras_inherent

@command-bot
Copy link

command-bot bot commented Mar 13, 2024

"$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=runtime_parachains::paras_inherent was queued.

Comment bot cancel 9-bb67ca25-f727-4aec-a7b8-4c43a48363db to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Mar 13, 2024

@sandreim Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=runtime_parachains::paras_inherent has finished. Result:

ValidationError: "id" is required
ValidationError: "id" is required
{"message":{"base":["Reference not found"]}}

@sandreim
Copy link
Contributor Author

bot bench polkadot-pallet --runtime=westend --pallet=runtime_parachains::paras_inherent

@command-bot
Copy link

command-bot bot commented Mar 13, 2024

"$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=runtime_parachains::paras_inherent was queued.

Comment bot cancel 10-64f6bfcf-a5ef-4548-be6c-b2b52deb992a to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Mar 13, 2024

@sandreim Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=runtime_parachains::paras_inherent has finished. Result:

ValidationError: "id" is required
ValidationError: "id" is required
{"message":{"base":["Reference not found"]}}

@ggwpez
Copy link
Member

ggwpez commented Mar 13, 2024

bot bench polkadot-pallet --runtime=westend --pallet=runtime_parachains::paras_inherent

@command-bot
Copy link

command-bot bot commented Mar 13, 2024

@ggwpez https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5517794 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=runtime_parachains::paras_inherent. Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 11-6a538673-4134-4af3-a596-3a70c41f3ad0 to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Mar 13, 2024

@ggwpez Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=runtime_parachains::paras_inherent has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5517794 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5517794/artifacts/download.

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
@sandreim sandreim force-pushed the sandreim/storage_map_overlay branch from dd1e8f9 to 728aa29 Compare March 13, 2024 16:07
@sandreim
Copy link
Contributor Author

bot bench polkadot-pallet --runtime=westend --pallet=runtime_parachains::paras_inherent

@command-bot
Copy link

command-bot bot commented Mar 13, 2024

@sandreim https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5520978 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=runtime_parachains::paras_inherent. Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 15-af575d13-ff31-4256-9a48-ef838166b0eb to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Mar 13, 2024

@sandreim Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=runtime_parachains::paras_inherent has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5520978 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5520978/artifacts/download.

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: cargo-clippy
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5523172

@@ -667,6 +691,11 @@ impl<T: Config> Pallet<T> {
disputes,
parent_header,
};

// Write back to storage only keys that have been updated or deleted.
for (para_id, candidates) in pending_availability_overlay.into_iter() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using a Drop instance like here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, good idea, I'll have to see how it should work in the case of this generic overlay.

{
// Construct a new overlay instance.
pub fn new() -> Self {
let data = P::populate();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we are doubling the memory footprint here, it would be really good if this improved performance by more than just a few percent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now it improves it by around 12% . I'd say it is not great, but that's what is currently possible. What kind of improvement are you expecting for the tradeoff to be worth it ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Depends on how tight we are on those axes. Time wise we are pretty good already. No idea about memory. Probably worth it.

But I just noticed something different: What this gains us, as far as I can see, is that it conflates two writes into one. At a quick glance it seems, that this should also easily be achievable by merging this mutate with the previous one. We are traversing them in order anyways. Instead of pushing to candidates_made_available, we could just enact immediately, if there were no holes (unavailable candidates in the loop before).

This should give us the same performance gain, but with half the memory consumption. @alindima what do you say?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll think about it a bit. In the first mutate, we update the availability votes. But when doing the enactments, we may enact more candidates than the ones that have been just made available in this block.
If for example we have A B C backed. B and C are already available. A is just being made available now. So we have to enact all candidates (A B and C).

That's why I chose to iterate twice there. I'll think more about it to see if we can call mutate only once for each para

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
@sandreim sandreim force-pushed the sandreim/storage_map_overlay branch from 6a43427 to 03841e1 Compare March 14, 2024 13:24
@sandreim
Copy link
Contributor Author

bot bench polkadot-pallet --runtime=westend --pallet=runtime_parachains::paras_inherent -v UPSTREAM_MERGE=n

@command-bot
Copy link

command-bot bot commented Mar 14, 2024

@sandreim https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5532841 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=runtime_parachains::paras_inherent. Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 1-73ab14b9-7697-44c3-af04-731a5ad89026 to cancel this command or bot cancel to cancel all commands in this pull request.

…=westend --target_dir=polkadot --pallet=runtime_parachains::paras_inherent
@command-bot
Copy link

command-bot bot commented Mar 14, 2024

@sandreim Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=runtime_parachains::paras_inherent has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5532841 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5532841/artifacts/download.

github-merge-queue bot pushed a commit that referenced this pull request Mar 15, 2024
Extracted Benchbuilder enhancements used in
#3644 . Might still
require some work to fully support all scenarios when disputing elastic
scaling parachains, but it should be useful in writing elastic scaling
runtime tests.

---------

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Base automatically changed from alindima/elastic-scaling-runtime to master March 21, 2024 10:44
dharjeezy pushed a commit to dharjeezy/polkadot-sdk that referenced this pull request Mar 24, 2024
…3690)

Extracted Benchbuilder enhancements used in
paritytech#3644 . Might still
require some work to fully support all scenarios when disputing elastic
scaling parachains, but it should be useful in writing elastic scaling
runtime tests.

---------

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
@sandreim sandreim closed this Aug 28, 2024
@sandreim sandreim deleted the sandreim/storage_map_overlay branch August 28, 2024 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants