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

perf(katana): optimisations + benchmark setup #2900

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

remybar
Copy link
Contributor

@remybar remybar commented Jan 13, 2025

Description

WIP

Related issue

#2719

Tests

  • Yes
  • No, because they aren't needed
  • No, because I need help

Added to documentation?

  • README.md
  • Dojo Book
  • No documentation needed

Checklist

  • I've formatted my code (scripts/prettier.sh, scripts/rust_fmt.sh, scripts/cairo_fmt.sh)
  • I've linted my code (scripts/clippy.sh, scripts/docs.sh)
  • I've commented my code
  • I've requested a review after addressing the comments

@glihm glihm changed the title katana: optimisations + benchmark setup perf(katana): optimisations + benchmark setup Jan 13, 2025
@remybar remybar force-pushed the katana-core-parallelized branch from e2dacee to 5519e6b Compare January 21, 2025 10:57
Copy link
Member

@kariy kariy left a comment

Choose a reason for hiding this comment

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

This benchmark includes data setup within the measured function (ie Uncommitted::commit). We should move the preparation of the test data (all the arguments for Uncommitted::new) outside the benchmark routine to ensure we're measuring only the commit operation's performance, not including the setup overhead.

We can use the Arbitrary trait to derive random values for the test data.

I'm not sure what's the best block composition but maybe we can start with something like 20 transactions, each with 2 events, and a state update of size 100.

@kariy
Copy link
Member

kariy commented Jan 21, 2025

I think what we should do, is have two .commit methods - the serialized and parallelized versions (ie .commit and .commit_parallel) - run two benchmarks against the same test vectors using each method.

@remybar remybar force-pushed the katana-core-parallelized branch from 5519e6b to 3728e6d Compare January 24, 2025 16:03
@remybar
Copy link
Contributor Author

remybar commented Jan 24, 2025

Hi @kariy !

So, I've kept 2 versions of optimized functions (original + parallel one) to be able to create commit and commit_parallel benches.

I used Arbitrary trait to generate random values (not sure if I used the idiomatic way to do this but ...) and set vector sizes to 20 for txs and receipts and 100 for state update stuff.

Maybe it would be a good idea to have 2 sets of data for these benches:

  • a first one with a tiny block to be sure that parallelizing block processings do not add any overhead,
  • a second one with a quite big block, as you proposed, to check that the performance improvement is worth it.

WDYT ?

@remybar remybar force-pushed the katana-core-parallelized branch from 3728e6d to e9aaea6 Compare January 24, 2025 16:11
@remybar remybar force-pushed the katana-core-parallelized branch from e9aaea6 to 347b9b0 Compare January 24, 2025 16:11
Copy link

codecov bot commented Jan 24, 2025

Codecov Report

Attention: Patch coverage is 1.51515% with 65 lines in your changes missing coverage. Please review.

Project coverage is 55.79%. Comparing base (8c484fd) to head (347b9b0).

Files with missing lines Patch % Lines
crates/katana/core/src/backend/mod.rs 1.51% 65 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2900      +/-   ##
==========================================
- Coverage   55.86%   55.79%   -0.07%     
==========================================
  Files         447      447              
  Lines       57859    57924      +65     
==========================================
- Hits        32323    32319       -4     
- Misses      25536    25605      +69     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@kariy kariy left a comment

Choose a reason for hiding this comment

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

Awesome work @remybar! It's looking good. Can we also include benchmark for block with only 1 tx and very small state updates - to mimic a small block (eg on instant mining when there's only 1 tx in a block)

});
}

criterion_group!(benches, commit_benchmark);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
criterion_group!(benches, commit_benchmark);
criterion_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
targets = commit_benchmark
}

let block =
UncommittedBlock::new(header, transactions, receipts.as_slice(), &state_updates, provider);

c.bench_function("commit", |b| {
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
c.bench_function("commit", |b| {
c.bench_function("Commit.Big.Serial", |b| {

b.iter_batched(|| block.clone(), |input| commit(black_box(input)), BatchSize::SmallInput);
});

c.bench_function("commit_parallel", |b| {
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
c.bench_function("commit_parallel", |b| {
c.bench_function("Commit.Big.Parallel", |b| {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants