Repository navigation
Performance and Benchmarks
github-actions[bot] edited this page Nov 29, 2026
·
2 revisions
Celly.Json is engineered for hot-path rule evaluation where expressions are compiled once and evaluated thousands to millions of times per second.
Measured on .NET 10.0.14 (X64 RyuJIT x86-64-v3), BenchmarkDotNet v0.15.8 with [MemoryDiagnoser], against a ~15 KB JSON payload containing a nested user object, 40 metadata fields, and a 100-item items array:
| Benchmark | Mean | Allocated | vs. Naive Eager |
|---|---|---|---|
Policy_NaiveEagerDictionary (baseline)
|
19,375.4 ns |
85,416 B |
1× |
Policy_CellyJson_EvalJson (JsonDocument) |
273.1 ns |
504 B |
71× faster, 169× less alloc |
Policy_CellyJson_ReusableActivation |
268.6 ns |
384 B |
72× faster, 222× less alloc |
Policy_CellyJson_JsonObject |
187.2 ns |
296 B |
103× faster, 288× less alloc |
Comprehension100_NaiveEagerDictionary |
55,508.1 ns |
214,680 B |
1× |
Comprehension100_CellyJson_ReusableActivation |
8,503.5 ns |
14,992 B |
6.5× faster, 14.3× less alloc |
| Benchmark | Mean | Allocated | Notes |
|---|---|---|---|
HttpContext_HeaderAndRolePolicy |
162.3 ns |
632 B |
Lazy HttpContextActivation + zero-list 'admin' in user.roles
|
HttpContext_WithJsonBodyPolicy |
602.0 ns |
656 B |
Includes ArrayPool<byte> body read, JsonDocument.Parse, rewind, and CEL eval |
CelJsonHttpResult_StreamToBodyWriter |
515.4 ns |
1,880 B |
Direct Utf8JsonWriter streaming (includes new DefaultHttpContext()) |
Translating user.age >= 18 && user.active && 'admin' in user.roles && items.exists(i, i.price >= 50 && i.qty > 0):
| Benchmark | Mean | Allocated |
|---|---|---|
Translate_MongoFilterJson |
610.7 ns |
1.47 KB |
Translate_CosmosSql |
990.8 ns |
4.13 KB |
Translate_SqliteJson |
1,227.1 ns |
5.63 KB |
Translate_SqlServerJson |
1,239.7 ns |
6.29 KB |
Translate_PostgresJsonb |
1,330.0 ns |
6.11 KB |
EndToEnd_ParseAndCosmosSql |
3,858.1 ns |
16.84 KB |
-
Zero eager materialization —
JsonElementObjectValueandJsonNodeObjectValueimplement Celly'sIStructValue,IIndexerValue,ISizedValue,IContainsTester, andIIterableValuedirectly. Unreferenced fields in a JSON payload are never decoded or allocated. -
Zero-allocation
inand==scans —JsonElementListValueimplementsIContainsTester.ContainsandEqualTooverJsonElement.EnumerateArray()usingJsonElement.ValueEquals(string)and direct primitive comparisons — avoiding UTF-8→UTF-16 string allocations,CelValueboxing, and$O(N^2)$ JsonElement[index]scans. -
Inline 4-slot activation cache —
JsonElementActivationandJsonNodeActivationcache up to 4 root variable lookups inline on the activation object (no heap array allocation), so repeated accesses likeuser.age,user.active, anduser.rolesshare a single wrapper. -
Native
ListValueintegration —JsonElementListValueandJsonNodeListValueinherit fromListValuewith lazyIReadOnlyList<CelValue>backing, giving full compatibility with Celly's$O(1)$ ropeConcatListValue([0] + arr). -
Direct
Utf8JsonWriterpass-through —CelJsonWritercallsJsonElement.WriteTo(writer)directly for unmodified JSON subtrees and formats durations on a stack-allocatedSpan<char>.
-
Compile
CelProgramonce and cache it (it is immutable and thread-safe). -
Reuse
JsonElementActivationper thread with.Reset(doc.RootElement)in tight loops (or useFilterJsonArray/FilterJsonLines, which do this for you). -
Avoid
EvalJson(string)inside hot loops if you already have aJsonDocumentorJsonObject— parsing JSON dominates the ~270 ns evaluation time. -
Keep
PropertyNameComparison = StringComparison.Ordinal(default) soJsonElement.TryGetPropertyuses its fast direct lookup path. -
Leave
JsonSchemaOptions.MapFormats = falseunless you actually need automaticdate-time/duration/bytedecoding.
Celly.Json — High-performance System.Text.Json adapter for Celly (.NET 10, NativeAOT-ready, MIT License).