From ff95fc859521e52a59386abc274eb78f42f519f4 Mon Sep 17 00:00:00 2001 From: "mongodb-sage-bot[bot]" <247496174+mongodb-sage-bot[bot]@users.noreply.github.com> Date: Fri, 5 Jun 2026 17:35:42 +0000 Subject: [PATCH 1/2] CSHARP-6064: Fix BsonEncodingPoco benchmark null bloat and stale DataSetSize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add [BsonIgnoreIfNull] to all four properties on DeepPocoNode to prevent serializing null fields that inflate BSON output by ~48%. Update the DataSetSize constant for deep_bson.json from 19_640_000 to 22_860_000 in both BsonEncodingBenchmark and BsonDecodingBenchmark to match the current file size (2,286 bytes per document × 10,000 iterations). --- .../MongoDB.Driver.Benchmarks/Bson/BsonBenchmarkDataTypes.cs | 4 ++++ .../MongoDB.Driver.Benchmarks/Bson/BsonDecodingBenchmark.cs | 2 +- .../MongoDB.Driver.Benchmarks/Bson/BsonEncodingBenchmark.cs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonBenchmarkDataTypes.cs b/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonBenchmarkDataTypes.cs index 67dce2c7f16..964cb4f6a76 100644 --- a/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonBenchmarkDataTypes.cs +++ b/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonBenchmarkDataTypes.cs @@ -320,9 +320,13 @@ public sealed class DeepPocoRoot public sealed class DeepPocoNode { + [BsonIgnoreIfNull] public DeepPocoNode right { get; set; } + [BsonIgnoreIfNull] public DeepPocoNode left { get; set; } + [BsonIgnoreIfNull] public string rightValue { get; set; } + [BsonIgnoreIfNull] public string leftValue { get; set; } } diff --git a/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonDecodingBenchmark.cs b/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonDecodingBenchmark.cs index 9495675f233..f2c9c984f86 100644 --- a/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonDecodingBenchmark.cs +++ b/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonDecodingBenchmark.cs @@ -80,6 +80,6 @@ public IEnumerable BenchmarkDataSources() => [ new("extended_bson/flat_bson.json", "Flat", 75_310_000, typeof(FlatPoco)), new("extended_bson/full_bson.json", "Full", 57_340_000, typeof(FullPoco)), - new("extended_bson/deep_bson.json", "Deep", 19_640_000, typeof(DeepPocoRoot)) + new("extended_bson/deep_bson.json", "Deep", 22_860_000, typeof(DeepPocoRoot)) ]; } diff --git a/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonEncodingBenchmark.cs b/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonEncodingBenchmark.cs index c0f6cba087e..68b97456163 100644 --- a/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonEncodingBenchmark.cs +++ b/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonEncodingBenchmark.cs @@ -82,6 +82,6 @@ public IEnumerable BenchmarkDataSources() => [ new("extended_bson/flat_bson.json", "Flat", 75_310_000, typeof(FlatPoco)), new("extended_bson/full_bson.json", "Full", 57_340_000, typeof(FullPoco)), - new("extended_bson/deep_bson.json", "Deep", 19_640_000, typeof(DeepPocoRoot)) + new("extended_bson/deep_bson.json", "Deep", 22_860_000, typeof(DeepPocoRoot)) ]; } From a334c7064846bfaece30b75cfbe39e713496f392 Mon Sep 17 00:00:00 2001 From: "mongodb-sage-bot[bot]" <247496174+mongodb-sage-bot[bot]@users.noreply.github.com> Date: Fri, 5 Jun 2026 18:09:22 +0000 Subject: [PATCH 2/2] CSHARP-6064: Fix deep_bson DataSetSize to 22_840_000 Corrected the deep_bson.json DataSetSize value from 22_860_000 to 22_840_000 in both BsonEncodingBenchmark.cs and BsonDecodingBenchmark.cs, as requested by @BorisDog. --- .../MongoDB.Driver.Benchmarks/Bson/BsonDecodingBenchmark.cs | 2 +- .../MongoDB.Driver.Benchmarks/Bson/BsonEncodingBenchmark.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonDecodingBenchmark.cs b/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonDecodingBenchmark.cs index f2c9c984f86..d91802a21b4 100644 --- a/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonDecodingBenchmark.cs +++ b/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonDecodingBenchmark.cs @@ -80,6 +80,6 @@ public IEnumerable BenchmarkDataSources() => [ new("extended_bson/flat_bson.json", "Flat", 75_310_000, typeof(FlatPoco)), new("extended_bson/full_bson.json", "Full", 57_340_000, typeof(FullPoco)), - new("extended_bson/deep_bson.json", "Deep", 22_860_000, typeof(DeepPocoRoot)) + new("extended_bson/deep_bson.json", "Deep", 22_840_000, typeof(DeepPocoRoot)) ]; } diff --git a/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonEncodingBenchmark.cs b/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonEncodingBenchmark.cs index 68b97456163..2f4f862c9f1 100644 --- a/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonEncodingBenchmark.cs +++ b/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonEncodingBenchmark.cs @@ -82,6 +82,6 @@ public IEnumerable BenchmarkDataSources() => [ new("extended_bson/flat_bson.json", "Flat", 75_310_000, typeof(FlatPoco)), new("extended_bson/full_bson.json", "Full", 57_340_000, typeof(FullPoco)), - new("extended_bson/deep_bson.json", "Deep", 22_860_000, typeof(DeepPocoRoot)) + new("extended_bson/deep_bson.json", "Deep", 22_840_000, typeof(DeepPocoRoot)) ]; }