Skip to content

Performance: default checkpoint generator issues one extra DB read per commit (AlwaysQueryDb) #76

Description

@AGiorgetti

Summary

MongoPersistenceEngine.Initialize() defaults to AlwaysQueryDbForNextValueCheckpointGenerator. That generator calls GetLastValue() on every Next() invocation — one extra MongoDB round-trip before every insert.

Why this matters

  • Write-heavy workloads pay an extra database read per commit on top of the insert.
  • The cost scales directly with commit volume.
  • Benchmarks show the always-query generator is ~47% slower than the in-memory generator for the same workload.

Baseline (net10, 2026-05-20)

Benchmark Mean
WriteWithCheckpointGenerator(CommitsToWrite=1000, GeneratorType=Always) 2,908.6 ms
WriteWithCheckpointGenerator(CommitsToWrite=1000, GeneratorType=InMemory) 1,541.0 ms

Delta: +89% overhead with the default always-query generator.

Proposed investigation

  • Confirm the round-trip overhead is the GetLastValue() call (not write contention).
  • Evaluate making InMemoryCheckpointGenerator the default, or using an atomic-increment strategy to avoid per-commit reads.
  • Verify concurrency correctness of any alternative approach (no checkpoint collisions under concurrent writers).

Reference

See docs/Performance-Investigation.md → Finding #4 for full context.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions