Skip to content

feat(dotnet): add .NET WASM evaluator package - #107

Merged
aepfli merged 2 commits into
mainfrom
feat/dotnet-package
Feb 20, 2026
Merged

aepfli merged 2 commits into
mainfrom
feat/dotnet-package

Conversation

@aepfli

@aepfli aepfli commented Feb 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds a .NET 8.0 package (dotnet/) wrapping the Rust WASM evaluator using Wasmtime for .NET v34.0.2
  • Implements the same optimized architecture as Java/Go packages: WASM instance pool, lock-free pre-evaluated cache, context key filtering, index-based evaluation, and generation guard
  • Includes 17 xunit tests (all passing), BenchmarkDotNet suite with evaluation + comparison benchmarks, Makefile, and README

Architecture

  • WASM Instance Pool: BlockingCollection<WasmInstance> sized to ProcessorCount for parallel evaluation
  • Pre-evaluated Cache: Static/disabled flags served lock-free via volatile reference swap (13 ns, zero alloc)
  • Context Key Filtering: Only serialize context keys referenced in targeting rules
  • Index-based Evaluation: evaluate_by_index(u32) avoids flag key string serialization
  • Generation Guard: Detects stale cache snapshots during concurrent UpdateState/EvaluateFlag
  • Prefix-based Host Function Matching: Survives wasm-bindgen hash suffix changes across WASM rebuilds

Comparison: WASM vs Old JsonLogic Provider (json-everything v5.4.0)

Scenario Old (JsonLogic) New (WASM) Speedup Memory
Simple flag (pre-eval) 38 ns / 72 B 13 ns / 0 B 2.9x 100% less
Targeting (small ctx) 6,993 ns / 7,120 B 5,082 ns / 592 B 1.4x 12x less
Targeting (empty ctx) 3,440 ns / 3,768 B 2,669 ns / 288 B 1.3x 13x less
Targeting (large ctx, 100+ attrs) 32,881 ns / 33,448 B 5,328 ns / 592 B 6.2x 56x less
8-thread large ctx 229,529 ns / 268 KB 105,425 ns / 5.6 KB 2.2x 48x less

Context key filtering gives the biggest win: with 100+ attributes, the old provider serializes everything (33 KB allocations), while the WASM evaluator only serializes the 2 keys referenced in targeting rules (592 B).

Standalone Evaluation Benchmarks

Benchmark Mean Allocated
PreEvaluated (static flag) 12.5 ns 0 B
SimpleTargeting SmallCtx 4.67 µs 568 B
SimpleTargeting LargeCtx 4.30 µs 568 B
ComplexTargeting SmallCtx 5.65 µs 584 B
ComplexTargeting LargeCtx 5.87 µs 584 B

Test plan

  • 17 xunit tests passing (bool/string/numeric flags, targeting, concurrency, generation guard, pool size 1)
  • BenchmarkDotNet evaluation + comparison suites run successfully
  • Verify make wasm && make build && make test from clean checkout

Closes #105

🤖 Generated with Claude Code

aepfli and others added 2 commits February 20, 2026 20:41
Implements .NET wrapper for the flagd-evaluator WASM module using
Wasmtime .NET v34.0.2 with the same architecture as the Go/Java packages:

- WASM instance pool (BlockingCollection, sized to ProcessorCount)
- Lock-free pre-evaluated cache via volatile reference swap
- Context key filtering (only serialize keys used in targeting rules)
- Index-based evaluation (evaluate_by_index avoids flag key serialization)
- Generation guard for safe race handling between UpdateState and EvaluateFlag
- Pre-allocated buffers (256B flag key + 1MB context per instance)
- Prefix-based host function matching (survives wasm-bindgen hash changes)
- 17 xunit tests including concurrency and generation guard
- BenchmarkDotNet suite with evaluation and concurrency benchmarks

Closes #105

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add MinimalInProcessResolver wrapping json-everything's JsonLogic (v5.4.0),
the same library used by the production flagd .NET provider. Comparison
benchmarks (X1-X5) mirror the Java/Go pattern: simple flags, targeting,
context size sweep, and concurrent evaluation.

Key results: WASM evaluator is 1.4x faster for targeting, 6.2x faster with
large contexts (100+ attrs), and allocates 56x less memory — context key
filtering avoids serializing unused attributes.

Closes #105

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aepfli
aepfli merged commit cb73a19 into main Feb 20, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(dotnet): add .NET package with Wasmtime WASM runtime, instance pool, and optimized evaluation

1 participant