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

Split Iter & IterByColRange types into Tx and MutTxId versions #2043

Merged
merged 5 commits into from
Dec 31, 2024

Conversation

mamcx
Copy link
Contributor

@mamcx mamcx commented Dec 9, 2024

Description of Changes

Refactor Iter / CommittedIndexIter for Tx & MutTx variants, and solves early the logic for decide the state machine.

Closes #2024

Expected complexity level and risk

1

Testing

Describe any testing you've done, and any testing you'd like your reviewers to do,
so that you're confident that all the changes work as expected!

  • Run benches with sudo nice -n -20 taskpolicy -B -t 5 -l 5 -c utility cargo bench --bench subscription -- --save-baseline subs

@mamcx mamcx requested a review from Centril December 9, 2024 18:09
@mamcx mamcx self-assigned this Dec 9, 2024
@mamcx
Copy link
Contributor Author

mamcx commented Dec 9, 2024

benchmarks please

Copy link

github-actions bot commented Dec 9, 2024

Benchmarking failed. Please check the workflow run for details.

Copy link

github-actions bot commented Dec 9, 2024

Callgrind benchmark results

Callgrind Benchmark Report

These benchmarks were run using callgrind,
an instruction-level profiler. They allow comparisons between sqlite (sqlite), SpacetimeDB running through a module (stdb_module), and the underlying SpacetimeDB data storage engine (stdb_raw). Callgrind emulates a CPU to collect the below estimates.

Measurement changes larger than five percent are in bold.

In-memory benchmarks

callgrind: empty transaction

db total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw 6403 6403 0.00% 6507 6541 -0.52%
sqlite 5627 5609 0.32% 6053 6083 -0.49%

callgrind: filter

db schema indices count preload _column data_type total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str no_index 64 128 1 u64 74361 74680 -0.43% 74821 75172 -0.47%
stdb_raw u32_u64_str no_index 64 128 2 string 116603 116922 -0.27% 117305 117728 -0.36%
stdb_raw u32_u64_str btree_each_column 64 128 2 string 24958 25090 -0.53% 25384 25688 -1.18%
stdb_raw u32_u64_str btree_each_column 64 128 1 u64 23924 24055 -0.54% 24340 24603 -1.07%
sqlite u32_u64_str no_index 64 128 2 string 144415 144415 0.00% 145791 145759 0.02%
sqlite u32_u64_str no_index 64 128 1 u64 123763 123763 0.00% 124909 124913 -0.00%
sqlite u32_u64_str btree_each_column 64 128 1 u64 131080 131080 0.00% 132582 132478 0.08%
sqlite u32_u64_str btree_each_column 64 128 2 string 134222 134222 0.00% 135882 135782 0.07%

callgrind: insert bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 64 128 811243 810725 0.06% 861557 830105 3.79%
stdb_raw u32_u64_str btree_each_column 64 128 1045837 1044485 0.13% 1075175 1070453 0.44%
sqlite u32_u64_str unique_0 64 128 399360 399360 0.00% 417498 416660 0.20%
sqlite u32_u64_str btree_each_column 64 128 984611 984611 0.00% 1019127 1027193 -0.79%

callgrind: iterate

db schema indices count total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 135368 138379 -2.18% 135488 138507 -2.18%
stdb_raw u32_u64_str unique_0 64 15673 15804 -0.83% 15773 15912 -0.87%
sqlite u32_u64_str unique_0 1024 1042718 1042718 0.00% 1046124 1045990 0.01%
sqlite u32_u64_str unique_0 64 74704 74722 -0.02% 75836 75780 0.07%

callgrind: serialize_product_value

count format total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
64 json 47528 47528 0.00% 50180 50316 -0.27%
64 bsatn 25509 25509 0.00% 27719 27787 -0.24%
16 bsatn 8200 8200 0.00% 9560 9628 -0.71%
16 json 12188 12188 0.00% 14092 14194 -0.72%

callgrind: update bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 1024 19140287 19148592 -0.04% 19808737 19673064 0.69%
stdb_raw u32_u64_str unique_0 64 128 1215762 1216617 -0.07% 1260662 1252777 0.63%
sqlite u32_u64_str unique_0 1024 1024 1802137 1802137 0.00% 1811123 1811383 -0.01%
sqlite u32_u64_str unique_0 64 128 128540 128540 0.00% 131374 131336 0.03%
On-disk benchmarks

callgrind: empty transaction

db total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw 6408 6408 0.00% 6508 6542 -0.52%
sqlite 5651 5651 0.00% 6095 6155 -0.97%

callgrind: filter

db schema indices count preload _column data_type total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str no_index 64 128 1 u64 74366 74685 -0.43% 74790 75145 -0.47%
stdb_raw u32_u64_str no_index 64 128 2 string 116608 116948 -0.29% 117154 117670 -0.44%
stdb_raw u32_u64_str btree_each_column 64 128 2 string 24961 25094 -0.53% 25351 25612 -1.02%
stdb_raw u32_u64_str btree_each_column 64 128 1 u64 23929 24060 -0.54% 24341 24556 -0.88%
sqlite u32_u64_str no_index 64 128 1 u64 125684 125684 0.00% 127210 127086 0.10%
sqlite u32_u64_str no_index 64 128 2 string 146336 146336 0.00% 148124 148072 0.04%
sqlite u32_u64_str btree_each_column 64 128 2 string 136418 136418 0.00% 138534 138366 0.12%
sqlite u32_u64_str btree_each_column 64 128 1 u64 133176 133176 0.00% 135018 134942 0.06%

callgrind: insert bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 64 128 759727 759592 0.02% 780301 778010 0.29%
stdb_raw u32_u64_str btree_each_column 64 128 997209 996145 0.11% 1056963 1051225 0.55%
sqlite u32_u64_str unique_0 64 128 416914 416914 0.00% 434478 433724 0.17%
sqlite u32_u64_str btree_each_column 64 128 1023158 1023176 -0.00% 1057382 1064640 -0.68%

callgrind: iterate

db schema indices count total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 135373 138384 -2.18% 135497 138512 -2.18%
stdb_raw u32_u64_str unique_0 64 15678 15809 -0.83% 15778 15937 -1.00%
sqlite u32_u64_str unique_0 1024 1045786 1045786 0.00% 1049594 1049404 0.02%
sqlite u32_u64_str unique_0 64 76476 76476 0.00% 77772 77710 0.08%

callgrind: serialize_product_value

count format total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
64 json 47528 47528 0.00% 50180 50316 -0.27%
64 bsatn 25509 25509 0.00% 27719 27787 -0.24%
16 bsatn 8200 8200 0.00% 9560 9628 -0.71%
16 json 12188 12188 0.00% 14092 14194 -0.72%

callgrind: update bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 1024 17629288 17637401 -0.05% 18343430 18205673 0.76%
stdb_raw u32_u64_str unique_0 64 128 1169015 1170817 -0.15% 1244609 1237195 0.60%
sqlite u32_u64_str unique_0 1024 1024 1809785 1809785 0.00% 1818507 1818479 0.00%
sqlite u32_u64_str unique_0 64 128 132687 132687 0.00% 135653 135607 0.03%

@mamcx mamcx requested a review from cloutiertyler as a code owner December 11, 2024 21:55
@mamcx mamcx force-pushed the mamcx/split-iter-by-tx branch from 4684925 to 0796849 Compare December 11, 2024 21:56
Copy link
Contributor

@Centril Centril left a comment

Choose a reason for hiding this comment

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

Almost there, this is looking very promising in terms of performance improvements.

@mamcx mamcx force-pushed the mamcx/split-iter-by-tx branch from ea1c16f to c4f7934 Compare December 12, 2024 16:54
@mamcx mamcx force-pushed the mamcx/split-iter-by-tx branch from c4f7934 to ba55f96 Compare December 13, 2024 14:22
@mamcx mamcx force-pushed the mamcx/split-iter-by-tx branch from ba55f96 to d5baa13 Compare December 19, 2024 17:24
Copy link
Contributor

@Centril Centril left a comment

Choose a reason for hiding this comment

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

Looks good now :)

@bfops bfops added the release-any To be landed in any release window label Dec 30, 2024
Copy link
Contributor

@cloutiertyler cloutiertyler left a comment

Choose a reason for hiding this comment

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

I've reviewed just what I am the code owner of. The changes to the datastore trait look good to me.

@mamcx mamcx added this pull request to the merge queue Dec 31, 2024
Merged via the queue into master with commit 20d397c Dec 31, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-1.0 release-any To be landed in any release window
Projects
None yet
Development

Successfully merging this pull request may close these issues.

perf: split Iter & IterByColRange types into Tx and MutTxId versions
4 participants