Skip to content

Commit

Permalink
No Maps for you! (#1770)
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril authored Oct 15, 2024
1 parent c4e637e commit 06cc688
Show file tree
Hide file tree
Showing 46 changed files with 35 additions and 935 deletions.
2 changes: 0 additions & 2 deletions crates/bindings-csharp/BSATN.Codegen/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ static string GetTypeInfoForNamedType(INamedTypeSymbol type)
"SpacetimeDB.I256" => "SpacetimeDB.BSATN.I256",
"SpacetimeDB.U256" => "SpacetimeDB.BSATN.U256",
"System.Collections.Generic.List<T>" => $"SpacetimeDB.BSATN.List",
"System.Collections.Generic.Dictionary<TKey, TValue>" =>
$"SpacetimeDB.BSATN.Dictionary",
// If we're here, then this is nullable *value* type like `int?`.
"System.Nullable<T>" => $"SpacetimeDB.BSATN.ValueOption",
var name when name.StartsWith("System.") => throw new InvalidOperationException(
Expand Down
8 changes: 0 additions & 8 deletions crates/bindings-csharp/BSATN.Runtime/BSATN/AlgebraicType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,13 @@ public partial struct AggregateElement(string? name, AlgebraicType algebraicType
public AlgebraicType AlgebraicType = algebraicType;
}

[SpacetimeDB.Type]
public partial struct MapElement(AlgebraicType key, AlgebraicType value)
{
public AlgebraicType Key = key;
public AlgebraicType Value = value;
}

[SpacetimeDB.Type]
public partial record AlgebraicType
: SpacetimeDB.TaggedEnum<(
int Ref,
AggregateElement[] Sum,
AggregateElement[] Product,
AlgebraicType Array,
MapElement Map,
Unit String,
Unit Bool,
Unit I8,
Expand Down
35 changes: 0 additions & 35 deletions crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,38 +438,3 @@ public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) =>
public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) =>
enumerable.GetAlgebraicType(registrar);
}

public readonly struct Dictionary<Key, Value, KeyRW, ValueRW> : IReadWrite<Dictionary<Key, Value>>
where Key : notnull
where KeyRW : IReadWrite<Key>, new()
where ValueRW : IReadWrite<Value>, new()
{
private static readonly KeyRW keyRW = new();
private static readonly ValueRW valueRW = new();

public Dictionary<Key, Value> Read(BinaryReader reader)
{
var count = reader.ReadInt32();
var result = new Dictionary<Key, Value>(count);
for (var i = 0; i < count; i++)
{
result.Add(keyRW.Read(reader), valueRW.Read(reader));
}
return result;
}

public void Write(BinaryWriter writer, Dictionary<Key, Value> value)
{
writer.Write(value.Count);
foreach (var (key, val) in value)
{
keyRW.Write(writer, key);
valueRW.Write(writer, val);
}
}

public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) =>
new AlgebraicType.Map(
new(keyRW.GetAlgebraicType(registrar), valueRW.GetAlgebraicType(registrar))
);
}
2 changes: 0 additions & 2 deletions crates/bindings-csharp/Codegen.Tests/fixtures/client/Lib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public partial struct PublicTable
public CustomEnum CustomEnumField;
public CustomTaggedEnum CustomTaggedEnumField;
public List<int> ListField;
public Dictionary<string, int> DictionaryField;
public int? NullableValueField;
public string? NullableReferenceField;
public Dictionary<CustomEnum, List<int?>?>? ComplexNestedField;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ public void ReadFields(System.IO.BinaryReader reader)
CustomEnumField = BSATN.CustomEnumField.Read(reader);
CustomTaggedEnumField = BSATN.CustomTaggedEnumField.Read(reader);
ListField = BSATN.ListField.Read(reader);
DictionaryField = BSATN.DictionaryField.Read(reader);
NullableValueField = BSATN.NullableValueField.Read(reader);
NullableReferenceField = BSATN.NullableReferenceField.Read(reader);
ComplexNestedField = BSATN.ComplexNestedField.Read(reader);
}

public void WriteFields(System.IO.BinaryWriter writer)
Expand Down Expand Up @@ -60,10 +58,8 @@ public void WriteFields(System.IO.BinaryWriter writer)
BSATN.CustomEnumField.Write(writer, CustomEnumField);
BSATN.CustomTaggedEnumField.Write(writer, CustomTaggedEnumField);
BSATN.ListField.Write(writer, ListField);
BSATN.DictionaryField.Write(writer, DictionaryField);
BSATN.NullableValueField.Write(writer, NullableValueField);
BSATN.NullableReferenceField.Write(writer, NullableReferenceField);
BSATN.ComplexNestedField.Write(writer, ComplexNestedField);
}

public readonly partial struct BSATN : SpacetimeDB.BSATN.IReadWrite<PublicTable>
Expand Down Expand Up @@ -92,12 +88,6 @@ public void WriteFields(System.IO.BinaryWriter writer)
internal static readonly CustomTaggedEnum.BSATN CustomTaggedEnumField = new();
internal static readonly SpacetimeDB.BSATN.List<int, SpacetimeDB.BSATN.I32> ListField =
new();
internal static readonly SpacetimeDB.BSATN.Dictionary<
string,
int,
SpacetimeDB.BSATN.String,
SpacetimeDB.BSATN.I32
> DictionaryField = new();
internal static readonly SpacetimeDB.BSATN.ValueOption<
int,
SpacetimeDB.BSATN.I32
Expand All @@ -106,24 +96,6 @@ internal static readonly SpacetimeDB.BSATN.RefOption<
string,
SpacetimeDB.BSATN.String
> NullableReferenceField = new();
internal static readonly SpacetimeDB.BSATN.RefOption<
System.Collections.Generic.Dictionary<
CustomEnum,
System.Collections.Generic.List<int?>?
>,
SpacetimeDB.BSATN.Dictionary<
CustomEnum,
System.Collections.Generic.List<int?>?,
SpacetimeDB.BSATN.Enum<CustomEnum>,
SpacetimeDB.BSATN.RefOption<
System.Collections.Generic.List<int?>,
SpacetimeDB.BSATN.List<
int?,
SpacetimeDB.BSATN.ValueOption<int, SpacetimeDB.BSATN.I32>
>
>
>
> ComplexNestedField = new();

public PublicTable Read(System.IO.BinaryReader reader) =>
SpacetimeDB.BSATN.IStructuralReadWrite.Read<PublicTable>(reader);
Expand Down Expand Up @@ -165,13 +137,11 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar
CustomTaggedEnumField.GetAlgebraicType(registrar)
),
new(nameof(ListField), ListField.GetAlgebraicType(registrar)),
new(nameof(DictionaryField), DictionaryField.GetAlgebraicType(registrar)),
new(nameof(NullableValueField), NullableValueField.GetAlgebraicType(registrar)),
new(
nameof(NullableReferenceField),
NullableReferenceField.GetAlgebraicType(registrar)
),
new(nameof(ComplexNestedField), ComplexNestedField.GetAlgebraicType(registrar))
)
}
));
}
Expand Down
2 changes: 0 additions & 2 deletions crates/bindings-csharp/Codegen.Tests/fixtures/server/Lib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ public partial struct PublicTable
public CustomEnum CustomEnumField;
public CustomTaggedEnum CustomTaggedEnumField;
public List<int> ListField;
public Dictionary<string, int> DictionaryField;
public int? NullableValueField;
public string? NullableReferenceField;
public Dictionary<CustomEnum, List<int?>?>? ComplexNestedField;
}

public static partial class Reducers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ public void ReadFields(System.IO.BinaryReader reader)
CustomEnumField = BSATN.CustomEnumField.Read(reader);
CustomTaggedEnumField = BSATN.CustomTaggedEnumField.Read(reader);
ListField = BSATN.ListField.Read(reader);
DictionaryField = BSATN.DictionaryField.Read(reader);
NullableValueField = BSATN.NullableValueField.Read(reader);
NullableReferenceField = BSATN.NullableReferenceField.Read(reader);
ComplexNestedField = BSATN.ComplexNestedField.Read(reader);
}

public void WriteFields(System.IO.BinaryWriter writer)
Expand Down Expand Up @@ -66,10 +64,8 @@ public void WriteFields(System.IO.BinaryWriter writer)
BSATN.CustomEnumField.Write(writer, CustomEnumField);
BSATN.CustomTaggedEnumField.Write(writer, CustomTaggedEnumField);
BSATN.ListField.Write(writer, ListField);
BSATN.DictionaryField.Write(writer, DictionaryField);
BSATN.NullableValueField.Write(writer, NullableValueField);
BSATN.NullableReferenceField.Write(writer, NullableReferenceField);
BSATN.ComplexNestedField.Write(writer, ComplexNestedField);
}

public readonly partial struct BSATN : SpacetimeDB.BSATN.IReadWrite<PublicTable>
Expand Down Expand Up @@ -101,12 +97,6 @@ public void WriteFields(System.IO.BinaryWriter writer)
internal static readonly CustomTaggedEnum.BSATN CustomTaggedEnumField = new();
internal static readonly SpacetimeDB.BSATN.List<int, SpacetimeDB.BSATN.I32> ListField =
new();
internal static readonly SpacetimeDB.BSATN.Dictionary<
string,
int,
SpacetimeDB.BSATN.String,
SpacetimeDB.BSATN.I32
> DictionaryField = new();
internal static readonly SpacetimeDB.BSATN.ValueOption<
int,
SpacetimeDB.BSATN.I32
Expand All @@ -115,24 +105,6 @@ internal static readonly SpacetimeDB.BSATN.RefOption<
string,
SpacetimeDB.BSATN.String
> NullableReferenceField = new();
internal static readonly SpacetimeDB.BSATN.RefOption<
System.Collections.Generic.Dictionary<
CustomEnum,
System.Collections.Generic.List<int?>?
>,
SpacetimeDB.BSATN.Dictionary<
CustomEnum,
System.Collections.Generic.List<int?>?,
SpacetimeDB.BSATN.Enum<CustomEnum>,
SpacetimeDB.BSATN.RefOption<
System.Collections.Generic.List<int?>,
SpacetimeDB.BSATN.List<
int?,
SpacetimeDB.BSATN.ValueOption<int, SpacetimeDB.BSATN.I32>
>
>
>
> ComplexNestedField = new();

public PublicTable Read(System.IO.BinaryReader reader) =>
SpacetimeDB.BSATN.IStructuralReadWrite.Read<PublicTable>(reader);
Expand Down Expand Up @@ -177,13 +149,11 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar
CustomTaggedEnumField.GetAlgebraicType(registrar)
),
new(nameof(ListField), ListField.GetAlgebraicType(registrar)),
new(nameof(DictionaryField), DictionaryField.GetAlgebraicType(registrar)),
new(nameof(NullableValueField), NullableValueField.GetAlgebraicType(registrar)),
new(
nameof(NullableReferenceField),
NullableReferenceField.GetAlgebraicType(registrar)
),
new(nameof(ComplexNestedField), ComplexNestedField.GetAlgebraicType(registrar))
)
}
));
}
Expand Down Expand Up @@ -235,21 +205,13 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar
BSATN.CustomTaggedEnumField.GetAlgebraicType(registrar)
),
new(nameof(ListField), BSATN.ListField.GetAlgebraicType(registrar)),
new(
nameof(DictionaryField),
BSATN.DictionaryField.GetAlgebraicType(registrar)
),
new(
nameof(NullableValueField),
BSATN.NullableValueField.GetAlgebraicType(registrar)
),
new(
nameof(NullableReferenceField),
BSATN.NullableReferenceField.GetAlgebraicType(registrar)
),
new(
nameof(ComplexNestedField),
BSATN.ComplexNestedField.GetAlgebraicType(registrar)
)
],
Indexes: [],
Expand Down
7 changes: 0 additions & 7 deletions crates/cli/src/subcommands/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,6 @@ mod write_type {
write_type(ctx, out, elem_ty)?;
write!(out, ">")?;
}
AlgebraicType::Map(ty) => {
write!(out, "Map<")?;
write_type(ctx, out, &ty.key_ty)?;
write!(out, ", ")?;
write_type(ctx, out, &ty.ty)?;
write!(out, ">")?;
}
AlgebraicType::Ref(r) => {
write!(out, "{}", ctx(*r))?;
}
Expand Down
18 changes: 4 additions & 14 deletions crates/cli/src/subcommands/generate/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ fn scalar_or_string_name(b: &AlgebraicType) -> Option<&str> {
AlgebraicType::String => "string",
AlgebraicType::F32 => "float",
AlgebraicType::F64 => "double",
AlgebraicType::Ref(_)
| AlgebraicType::Sum(_)
| AlgebraicType::Product(_)
| AlgebraicType::Array(_)
| AlgebraicType::Map(_) => return None,
AlgebraicType::Ref(_) | AlgebraicType::Sum(_) | AlgebraicType::Product(_) | AlgebraicType::Array(_) => {
return None
}
})
}

Expand All @@ -64,14 +62,6 @@ fn ty_fmt<'a>(ctx: &'a GenCtx, ty: &'a AlgebraicType, namespace: &'a str) -> imp
ty_fmt(ctx, elem_ty, namespace)
)
}
AlgebraicType::Map(ty) => {
write!(
f,
"System.Collections.Generic.Dictionary<{}, {}>",
ty_fmt(ctx, &ty.ty, namespace),
ty_fmt(ctx, &ty.key_ty, namespace)
)
}
AlgebraicType::Ref(r) => {
let name = csharp_typename(ctx, *r);
match &ctx.typespace[*r] {
Expand Down Expand Up @@ -105,7 +95,7 @@ fn default_init(ctx: &GenCtx, ty: &AlgebraicType) -> Option<&'static str> {
// TODO: generate some proper default here (what would it be for tagged enums?).
AlgebraicType::Sum(_) => Some("null!"),
// For product types, arrays, and maps, we can use the default constructor.
AlgebraicType::Product(_) | AlgebraicType::Array(_) | AlgebraicType::Map(_) => Some("new()"),
AlgebraicType::Product(_) | AlgebraicType::Array(_) => Some("new()"),
// Strings must have explicit default value of "".
AlgebraicType::String => Some(r#""""#),
AlgebraicType::Ref(r) => default_init(ctx, &ctx.typespace[*r]),
Expand Down
1 change: 0 additions & 1 deletion crates/cli/src/subcommands/generate/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ pub fn write_type<W: Write>(module: &ModuleDef, out: &mut W, ty: &AlgebraicTypeU
write_type(module, out, elem_ty)?;
write!(out, ">")?;
}
AlgebraicTypeUse::Map { .. } => unimplemented!("AlgebraicType::Map is unsupported and will be removed"),
AlgebraicTypeUse::Ref(r) => {
write!(out, "{}", type_ref_name(module, *r))?;
}
Expand Down
2 changes: 0 additions & 2 deletions crates/cli/src/subcommands/generate/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,6 @@ pub fn write_type<W: Write>(
write_type(module, out, elem_ty, ref_prefix)?;
write!(out, "[]")?;
}
AlgebraicTypeUse::Map { .. } => unimplemented!("AlgebraicType::Map is unsupported and will be removed"),
AlgebraicTypeUse::Ref(r) => {
if let Some(prefix) = ref_prefix {
write!(out, "{prefix}")?;
Expand Down Expand Up @@ -978,7 +977,6 @@ fn convert_algebraic_type<'a>(
AlgebraicTypeUse::Primitive(prim) => {
write!(out, "AlgebraicType.create{prim:?}Type()");
}
AlgebraicTypeUse::Map { .. } => unimplemented!(),
AlgebraicTypeUse::Unit => write!(out, "AlgebraicType.createProductType([])"),
AlgebraicTypeUse::Never => unimplemented!(),
AlgebraicTypeUse::String => write!(out, "AlgebraicType.createStringType()"),
Expand Down
Loading

2 comments on commit 06cc688

@github-actions
Copy link

@github-actions github-actions bot commented on 06cc688 Oct 15, 2024

Choose a reason for hiding this comment

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

Criterion benchmark results

Criterion benchmark report

YOU SHOULD PROBABLY IGNORE THESE RESULTS.

Criterion is a wall time based benchmarking system that is extremely noisy when run on CI. We collect these results for longitudinal analysis, but they are not reliable for comparing individual PRs.

Go look at the callgrind report instead.

empty

db on disk new latency old latency new throughput old throughput
sqlite 💿 419.1±1.23ns 406.8±1.68ns - -
sqlite 🧠 418.7±3.78ns 405.5±1.20ns - -
stdb_raw 💿 631.1±0.81ns 621.5±3.79ns - -
stdb_raw 🧠 625.8±0.56ns 620.2±1.34ns - -

insert_1

db on disk schema indices preload new latency old latency new throughput old throughput

insert_bulk

db on disk schema indices preload count new latency old latency new throughput old throughput
sqlite 💿 u32_u64_str btree_each_column 2048 256 588.6±1.41µs 601.7±59.59µs 1698 tx/sec 1661 tx/sec
sqlite 💿 u32_u64_str unique_0 2048 256 150.6±0.73µs 149.2±0.46µs 6.5 Ktx/sec 6.5 Ktx/sec
sqlite 💿 u32_u64_u64 btree_each_column 2048 256 489.4±42.73µs 465.2±0.43µs 2043 tx/sec 2.1 Ktx/sec
sqlite 💿 u32_u64_u64 unique_0 2048 256 135.7±0.59µs 134.2±0.47µs 7.2 Ktx/sec 7.3 Ktx/sec
sqlite 🧠 u32_u64_str btree_each_column 2048 256 450.7±3.18µs 446.9±1.15µs 2.2 Ktx/sec 2.2 Ktx/sec
sqlite 🧠 u32_u64_str unique_0 2048 256 123.4±0.55µs 121.5±0.35µs 7.9 Ktx/sec 8.0 Ktx/sec
sqlite 🧠 u32_u64_u64 btree_each_column 2048 256 371.0±0.70µs 367.6±1.04µs 2.6 Ktx/sec 2.7 Ktx/sec
sqlite 🧠 u32_u64_u64 unique_0 2048 256 104.1±0.67µs 100.7±1.24µs 9.4 Ktx/sec 9.7 Ktx/sec
stdb_raw 💿 u32_u64_str btree_each_column 2048 256 647.0±28.96µs 648.3±25.82µs 1545 tx/sec 1542 tx/sec
stdb_raw 💿 u32_u64_str unique_0 2048 256 501.8±31.42µs 488.4±31.95µs 1992 tx/sec 2047 tx/sec
stdb_raw 💿 u32_u64_u64 btree_each_column 2048 256 344.0±9.66µs 341.5±4.94µs 2.8 Ktx/sec 2.9 Ktx/sec
stdb_raw 💿 u32_u64_u64 unique_0 2048 256 350.5±13.39µs 358.6±7.29µs 2.8 Ktx/sec 2.7 Ktx/sec
stdb_raw 🧠 u32_u64_str btree_each_column 2048 256 313.5±0.70µs 309.6±0.36µs 3.1 Ktx/sec 3.2 Ktx/sec
stdb_raw 🧠 u32_u64_str unique_0 2048 256 244.6±0.20µs 240.8±0.20µs 4.0 Ktx/sec 4.1 Ktx/sec
stdb_raw 🧠 u32_u64_u64 btree_each_column 2048 256 254.0±0.13µs 246.4±0.20µs 3.8 Ktx/sec 4.0 Ktx/sec
stdb_raw 🧠 u32_u64_u64 unique_0 2048 256 225.2±0.11µs 220.8±0.34µs 4.3 Ktx/sec 4.4 Ktx/sec

iterate

db on disk schema indices new latency old latency new throughput old throughput
sqlite 💿 u32_u64_str unique_0 22.7±0.08µs 22.6±0.12µs 43.0 Ktx/sec 43.3 Ktx/sec
sqlite 💿 u32_u64_u64 unique_0 21.5±0.15µs 21.3±0.10µs 45.4 Ktx/sec 45.8 Ktx/sec
sqlite 🧠 u32_u64_str unique_0 20.2±0.11µs 19.9±0.11µs 48.3 Ktx/sec 49.1 Ktx/sec
sqlite 🧠 u32_u64_u64 unique_0 19.0±0.05µs 18.6±0.06µs 51.3 Ktx/sec 52.6 Ktx/sec
stdb_raw 💿 u32_u64_str unique_0 4.7±0.00µs 4.7±0.00µs 206.3 Ktx/sec 206.0 Ktx/sec
stdb_raw 💿 u32_u64_u64 unique_0 4.6±0.00µs 4.6±0.00µs 211.2 Ktx/sec 210.6 Ktx/sec
stdb_raw 🧠 u32_u64_str unique_0 4.7±0.00µs 4.8±0.00µs 206.7 Ktx/sec 205.6 Ktx/sec
stdb_raw 🧠 u32_u64_u64 unique_0 4.6±0.00µs 4.6±0.00µs 211.1 Ktx/sec 210.5 Ktx/sec

find_unique

db on disk key type preload new latency old latency new throughput old throughput

filter

db on disk key type index strategy load count new latency old latency new throughput old throughput
sqlite 💿 string index 2048 256 68.5±0.19µs 69.5±0.41µs 14.3 Ktx/sec 14.1 Ktx/sec
sqlite 💿 u64 index 2048 256 65.3±0.12µs 68.1±0.50µs 15.0 Ktx/sec 14.3 Ktx/sec
sqlite 🧠 string index 2048 256 65.1±0.07µs 67.1±0.24µs 15.0 Ktx/sec 14.6 Ktx/sec
sqlite 🧠 u64 index 2048 256 60.9±0.13µs 61.8±0.27µs 16.0 Ktx/sec 15.8 Ktx/sec
stdb_raw 💿 string index 2048 256 4.9±0.00µs 4.9±0.00µs 198.9 Ktx/sec 198.0 Ktx/sec
stdb_raw 💿 u64 index 2048 256 4.8±0.00µs 4.7±0.00µs 203.6 Ktx/sec 207.7 Ktx/sec
stdb_raw 🧠 string index 2048 256 4.9±0.00µs 4.9±0.00µs 199.1 Ktx/sec 197.9 Ktx/sec
stdb_raw 🧠 u64 index 2048 256 4.8±0.00µs 4.7±0.00µs 203.5 Ktx/sec 207.8 Ktx/sec

serialize

schema format count new latency old latency new throughput old throughput
u32_u64_str bflatn_to_bsatn_fast_path 100 3.2±0.01µs 3.3±0.01µs 29.4 Mtx/sec 29.3 Mtx/sec
u32_u64_str bflatn_to_bsatn_slow_path 100 3.4±0.01µs 3.4±0.00µs 28.2 Mtx/sec 28.1 Mtx/sec
u32_u64_str bsatn 100 2.4±0.00µs 2.4±0.03µs 39.4 Mtx/sec 40.5 Mtx/sec
u32_u64_str bsatn 100 40.5±0.07ns 40.6±0.10ns 2.3 Gtx/sec 2.3 Gtx/sec
u32_u64_str json 100 4.9±0.06µs 4.7±0.02µs 19.7 Mtx/sec 20.2 Mtx/sec
u32_u64_str json 100 8.6±0.00µs 7.0±0.04µs 11.1 Mtx/sec 13.6 Mtx/sec
u32_u64_str product_value 100 1016.3±1.71ns 1015.9±1.08ns 93.8 Mtx/sec 93.9 Mtx/sec
u32_u64_u64 bflatn_to_bsatn_fast_path 100 1176.0±9.36ns 1126.1±1.39ns 81.1 Mtx/sec 84.7 Mtx/sec
u32_u64_u64 bflatn_to_bsatn_slow_path 100 2.8±0.00µs 2.8±0.01µs 34.2 Mtx/sec 34.2 Mtx/sec
u32_u64_u64 bsatn 100 1770.9±32.32ns 1690.9±34.26ns 53.9 Mtx/sec 56.4 Mtx/sec
u32_u64_u64 bsatn 100 28.8±0.10ns 39.3±0.16ns 3.2 Gtx/sec 2.4 Gtx/sec
u32_u64_u64 json 100 3.1±0.06µs 3.1±0.06µs 30.7 Mtx/sec 31.0 Mtx/sec
u32_u64_u64 json 100 4.8±0.01µs 4.8±0.01µs 20.0 Mtx/sec 19.7 Mtx/sec
u32_u64_u64 product_value 100 1013.2±3.64ns 1014.0±1.72ns 94.1 Mtx/sec 94.0 Mtx/sec
u64_u64_u32 bflatn_to_bsatn_fast_path 100 919.6±1.68ns 899.3±2.02ns 103.7 Mtx/sec 106.1 Mtx/sec
u64_u64_u32 bflatn_to_bsatn_slow_path 100 2.8±0.00µs 2.8±0.01µs 34.2 Mtx/sec 34.2 Mtx/sec
u64_u64_u32 bsatn 100 1756.7±25.45ns 1651.1±34.21ns 54.3 Mtx/sec 57.8 Mtx/sec
u64_u64_u32 bsatn 100 751.1±0.45ns 1080.3±1.60ns 127.0 Mtx/sec 88.3 Mtx/sec
u64_u64_u32 json 100 3.5±0.08µs 3.3±0.06µs 27.3 Mtx/sec 29.2 Mtx/sec
u64_u64_u32 json 100 4.7±0.01µs 6.6±0.00µs 20.5 Mtx/sec 14.5 Mtx/sec
u64_u64_u32 product_value 100 1015.6±0.94ns 1021.8±0.70ns 93.9 Mtx/sec 93.3 Mtx/sec

stdb_module_large_arguments

arg size new latency old latency new throughput old throughput
64KiB 116.3±7.34µs 108.6±11.83µs - -

stdb_module_print_bulk

line count new latency old latency new throughput old throughput
1 49.8±7.33µs 57.7±6.41µs - -
100 598.2±3.89µs 609.0±7.49µs - -
1000 3.6±0.14ms 5.4±0.15ms - -

remaining

name new latency old latency new throughput old throughput
special/db_game/circles/load=10 293.3±3.59µs 300.8±2.14µs - -
special/db_game/circles/load=100 293.1±3.70µs 300.2±2.25µs - -
special/db_game/ia_loop/load=10 0.0±0.00ns 0.0±0.00ns - -
special/db_game/ia_loop/load=100 0.0±0.00ns 0.0±0.00ns - -
sqlite/💿/update_bulk/u32_u64_str/unique_0/load=2048/count=256 53.5±0.17µs 53.1±0.11µs 18.2 Ktx/sec 18.4 Ktx/sec
sqlite/💿/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 45.5±0.12µs 46.5±0.16µs 21.4 Ktx/sec 21.0 Ktx/sec
sqlite/🧠/update_bulk/u32_u64_str/unique_0/load=2048/count=256 39.1±0.09µs 38.6±0.08µs 25.0 Ktx/sec 25.3 Ktx/sec
sqlite/🧠/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 35.2±0.06µs 35.5±0.18µs 27.7 Ktx/sec 27.5 Ktx/sec
stdb_module/💿/update_bulk/u32_u64_str/unique_0/load=2048/count=256 1297.1±18.69µs 1303.7±8.21µs 770 tx/sec 767 tx/sec
stdb_module/💿/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 1014.2±6.09µs 1047.6±6.60µs 986 tx/sec 954 tx/sec
stdb_raw/💿/update_bulk/u32_u64_str/unique_0/load=2048/count=256 548.9±11.30µs 650.5±9.99µs 1821 tx/sec 1537 tx/sec
stdb_raw/💿/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 457.7±7.12µs 489.6±9.49µs 2.1 Ktx/sec 2042 tx/sec
stdb_raw/🧠/update_bulk/u32_u64_str/unique_0/load=2048/count=256 375.5±0.23µs 374.8±0.36µs 2.6 Ktx/sec 2.6 Ktx/sec
stdb_raw/🧠/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 339.4±0.73µs 338.3±0.79µs 2.9 Ktx/sec 2.9 Ktx/sec

@github-actions
Copy link

@github-actions github-actions bot commented on 06cc688 Oct 15, 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 5386 5382 0.07% 5482 5454 0.51%
sqlite 5575 5509 1.20% 5987 5947 0.67%

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 75577 75888 -0.41% 75985 76174 -0.25%
stdb_raw u32_u64_str no_index 64 128 2 string 118074 119516 -1.21% 118686 120004 -1.10%
stdb_raw u32_u64_str btree_each_column 64 128 2 string 24068 24007 0.25% 24484 24395 0.36%
stdb_raw u32_u64_str btree_each_column 64 128 1 u64 23036 22974 0.27% 23348 23300 0.21%
sqlite u32_u64_str no_index 64 128 2 string 144661 144668 -0.00% 146253 146056 0.13%
sqlite u32_u64_str no_index 64 128 1 u64 124011 124018 -0.01% 125295 125172 0.10%
sqlite u32_u64_str btree_each_column 64 128 1 u64 131338 131335 0.00% 132730 132641 0.07%
sqlite u32_u64_str btree_each_column 64 128 2 string 134460 134467 -0.01% 136096 135971 0.09%

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 902694 898924 0.42% 924852 914788 1.10%
stdb_raw u32_u64_str btree_each_column 64 128 1052026 1048788 0.31% 1123752 1107108 1.50%
sqlite u32_u64_str unique_0 64 128 398284 398284 0.00% 417850 414662 0.77%
sqlite u32_u64_str btree_each_column 64 128 983611 983601 0.00% 1030107 1021861 0.81%

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 152706 152812 -0.07% 152784 152870 -0.06%
stdb_raw u32_u64_str unique_0 64 15731 15837 -0.67% 15801 15883 -0.52%
sqlite u32_u64_str unique_0 1024 1067233 1046653 1.97% 1070657 1049929 1.97%
sqlite u32_u64_str unique_0 64 76179 74805 1.84% 77289 75807 1.95%

callgrind: serialize_product_value

count format total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
64 json 47182 47374 -0.41% 49736 49962 -0.45%
64 bsatn 25716 25716 0.00% 27960 28028 -0.24%
16 bsatn 8117 8117 0.00% 9477 9545 -0.71%
16 json 12078 12126 -0.40% 13880 13962 -0.59%

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 20724415 20681410 0.21% 21511781 21198520 1.48%
stdb_raw u32_u64_str unique_0 64 128 1307325 1307550 -0.02% 1391853 1376742 1.10%
sqlite u32_u64_str unique_0 1024 1024 1802083 1802091 -0.00% 1811283 1811661 -0.02%
sqlite u32_u64_str unique_0 64 128 128429 128437 -0.01% 131223 131163 0.05%
On-disk benchmarks

callgrind: empty transaction

db total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw 5396 5392 0.07% 5496 5468 0.51%
sqlite 5617 5551 1.19% 6097 6049 0.79%

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 75587 75898 -0.41% 75995 76184 -0.25%
stdb_raw u32_u64_str no_index 64 128 2 string 118084 118437 -0.30% 118756 118933 -0.15%
stdb_raw u32_u64_str btree_each_column 64 128 2 string 24079 24016 0.26% 24467 24404 0.26%
stdb_raw u32_u64_str btree_each_column 64 128 1 u64 23046 22984 0.27% 23358 23302 0.24%
sqlite u32_u64_str no_index 64 128 1 u64 125932 125939 -0.01% 127476 127405 0.06%
sqlite u32_u64_str no_index 64 128 2 string 146582 146589 -0.00% 148374 148269 0.07%
sqlite u32_u64_str btree_each_column 64 128 2 string 136582 136589 -0.01% 138692 138671 0.02%
sqlite u32_u64_str btree_each_column 64 128 1 u64 133424 133431 -0.01% 135262 135203 0.04%

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 851398 848792 0.31% 903460 894576 0.99%
stdb_raw u32_u64_str btree_each_column 64 128 998374 996010 0.24% 1066580 1052518 1.34%
sqlite u32_u64_str unique_0 64 128 415821 415821 0.00% 434709 431573 0.73%
sqlite u32_u64_str btree_each_column 64 128 1021895 1021862 0.00% 1066953 1058766 0.77%

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 152716 152822 -0.07% 152782 152868 -0.06%
stdb_raw u32_u64_str unique_0 64 15741 15847 -0.67% 15807 15893 -0.54%
sqlite u32_u64_str unique_0 1024 1070301 1049721 1.96% 1074055 1053475 1.95%
sqlite u32_u64_str unique_0 64 77951 76571 1.80% 79249 77817 1.84%

callgrind: serialize_product_value

count format total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
64 json 47182 47374 -0.41% 49736 49962 -0.45%
64 bsatn 25716 25716 0.00% 27960 28028 -0.24%
16 bsatn 8117 8117 0.00% 9477 9545 -0.71%
16 json 12078 12126 -0.40% 13880 13962 -0.59%

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 19420322 19380503 0.21% 20292528 19973025 1.60%
stdb_raw u32_u64_str unique_0 64 128 1261538 1258176 0.27% 1345734 1326076 1.48%
sqlite u32_u64_str unique_0 1024 1024 1809644 1809652 -0.00% 1818188 1818286 -0.01%
sqlite u32_u64_str unique_0 64 128 132555 132563 -0.01% 135401 135389 0.01%

Please sign in to comment.