Skip to content

Commit

Permalink
Implement the module rng proposal for C# (#1425)
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser authored Jun 17, 2024
1 parent 8a3364e commit 1d89643
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/bindings-csharp/Runtime/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ RawBindings.Buffer args
{
try
{
Runtime.Random = new((int)timestamp);
using var stream = new MemoryStream(args.Consume());
using var reader = new BinaryReader(stream);
reducers[(int)id].Invoke(
Expand Down
3 changes: 3 additions & 0 deletions crates/bindings-csharp/Runtime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,7 @@ T row
return false;
}
}

// An instance of `System.Random` that is reseeded by each reducer's timestamp.
public static Random Random { get; internal set; } = new();
}

3 comments on commit 1d89643

@github-actions
Copy link

@github-actions github-actions bot commented on 1d89643 Jun 17, 2024

Choose a reason for hiding this comment

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

Bot test failed. Please check the workflow run for details.

@github-actions
Copy link

@github-actions github-actions bot commented on 1d89643 Jun 17, 2024

Choose a reason for hiding this comment

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

Benchmarking failed. Please check the workflow run for details.

@github-actions
Copy link

@github-actions github-actions bot commented on 1d89643 Jun 17, 2024

Choose a reason for hiding this comment

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

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 5138 5138 0.00% 5244 5244 0.00%
sqlite 5528 5528 0.00% 5988 5988 0.00%

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 77832 77832 0.00% 78264 78264 0.00%
stdb_raw u32_u64_str no_index 64 128 2 string 120502 120502 0.00% 121122 121122 0.00%
stdb_raw u32_u64_str btree_each_column 64 128 1 u64 23066 23066 0.00% 23450 23450 0.00%
stdb_raw u32_u64_str btree_each_column 64 128 2 string 24107 24104 0.01% 24483 24480 0.01%
sqlite u32_u64_str no_index 64 128 2 string 143488 143488 0.00% 145070 145066 0.00%
sqlite u32_u64_str no_index 64 128 1 u64 122829 122829 0.00% 124103 124099 0.00%
sqlite u32_u64_str btree_each_column 64 128 2 string 133287 133287 0.00% 135041 135037 0.00%
sqlite u32_u64_str btree_each_column 64 128 1 u64 130146 130146 0.00% 131664 131664 0.00%

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 867630 867163 0.05% 883154 882651 0.06%
stdb_raw u32_u64_str btree_each_column 64 128 1010383 1010939 -0.05% 1032483 1033095 -0.06%
sqlite u32_u64_str unique_0 64 128 396151 396151 0.00% 411399 411399 0.00%
sqlite u32_u64_str btree_each_column 64 128 981473 981458 0.00% 1018051 1018032 0.00%

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 151301 151301 0.00% 151435 151435 0.00%
stdb_raw u32_u64_str unique_0 64 15286 15286 0.00% 15416 15416 0.00%
sqlite u32_u64_str unique_0 1024 1046680 1046680 0.00% 1049906 1049906 0.00%
sqlite u32_u64_str unique_0 64 74826 74826 0.00% 75760 75760 0.00%

callgrind: serialize_product_value

count format total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
64 json 47438 47438 0.00% 49992 49992 0.00%
64 bsatn 25716 25716 0.00% 27926 27926 0.00%
16 bsatn 8117 8117 0.00% 9409 9409 0.00%
16 json 12142 12142 0.00% 13948 13948 0.00%

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 19944011 19940874 0.02% 20429771 20426640 0.02%
stdb_raw u32_u64_str unique_0 64 128 1270318 1270769 -0.04% 1305130 1305585 -0.03%
sqlite u32_u64_str unique_0 1024 1024 1802046 1802046 0.00% 1811312 1811312 0.00%
sqlite u32_u64_str unique_0 64 128 128392 128392 0.00% 131320 131320 0.00%
On-disk benchmarks

callgrind: empty transaction

db total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw 5148 5148 0.00% 5254 5254 0.00%
sqlite 5566 5566 0.00% 6154 6154 0.00%

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 77842 77842 0.00% 78246 78246 0.00%
stdb_raw u32_u64_str no_index 64 128 2 string 120512 120512 0.00% 121072 121072 0.00%
stdb_raw u32_u64_str btree_each_column 64 128 1 u64 23076 23076 0.00% 23460 23460 0.00%
stdb_raw u32_u64_str btree_each_column 64 128 2 string 24114 24114 0.00% 24490 24490 0.00%
sqlite u32_u64_str no_index 64 128 1 u64 124750 124750 0.00% 126376 126376 0.00%
sqlite u32_u64_str no_index 64 128 2 string 145409 145409 0.00% 147295 147291 0.00%
sqlite u32_u64_str btree_each_column 64 128 1 u64 132242 132242 0.00% 134150 134154 -0.00%
sqlite u32_u64_str btree_each_column 64 128 2 string 135409 135409 0.00% 137549 137553 -0.00%

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 817201 817306 -0.01% 862929 863012 -0.01%
stdb_raw u32_u64_str btree_each_column 64 128 955262 956053 -0.08% 1006294 1007137 -0.08%
sqlite u32_u64_str unique_0 64 128 413678 413678 0.00% 428070 428074 -0.00%
sqlite u32_u64_str btree_each_column 64 128 1019729 1019729 0.00% 1054827 1054815 0.00%

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 151311 151311 0.00% 151437 151437 0.00%
stdb_raw u32_u64_str unique_0 64 15296 15296 0.00% 15426 15426 0.00%
sqlite u32_u64_str unique_0 1024 1049754 1049754 0.00% 1053610 1053610 0.00%
sqlite u32_u64_str unique_0 64 76598 76598 0.00% 77800 77800 0.00%

callgrind: serialize_product_value

count format total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
64 json 47438 47438 0.00% 49992 49992 0.00%
64 bsatn 25716 25716 0.00% 27926 27926 0.00%
16 bsatn 8117 8117 0.00% 9409 9409 0.00%
16 json 12142 12142 0.00% 13948 13948 0.00%

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 18890747 18893937 -0.02% 19445379 19448025 -0.01%
stdb_raw u32_u64_str unique_0 64 128 1226688 1226697 -0.00% 1291466 1291491 -0.00%
sqlite u32_u64_str unique_0 1024 1024 1809601 1809601 0.00% 1818289 1818289 0.00%
sqlite u32_u64_str unique_0 64 128 132512 132512 0.00% 135522 135522 0.00%

Please sign in to comment.