Skip to content

perf: use mimalloc for MongoDB connector allocations - #203

Draft
codedmart wants to merge 1 commit into
mainfrom
codedmart/mongodb-mimalloc
Draft

codedmart wants to merge 1 commit into
mainfrom
codedmart/mongodb-mimalloc

Conversation

@codedmart

Copy link
Copy Markdown
Contributor

Summary

Use mimalloc::MiMalloc as the Rust global allocator for the MongoDB connector binary, in addition to the immutable-configuration sharing already released in v2.1.5 / #201.

  • Add exactly mimalloc = "=0.1.52" to the connector package (libmimalloc-sys0.1.49, bundled mimalloc3.3.2).
  • Install the allocator in the connector binary entrypoint. CLI binaries and shared-library crates are unchanged.
  • Default allocator options only: no mi_collect, purge timer, preload, native malloc override, or tuning environment variables.
  • Three files only: connector manifest, binary entrypoint, Cargo.lock. Existing dependency versions/edges are preserved; the lock adds only the two allocator packages and the connector→mimalloc edge.
  • No SDK, configuration-sharing, query buffering, CI, version or release changes.

Fresh v2.1.5 measurements

All comparisons below use fresh source builds from the same v2.1.5 commit, identical Rust1.94.1/toolchain/runtime and workload limits, changing only the allocator. Every successful response was fully consumed and matched by byte count and SHA-256. Each final idle window is five minutes with zero active requests. No forced collection.

Synthetic workload System → mimalloc Qualification
12,001-type static schema, tiny responses; two reversed-order trials Median five-minute idle RSS191.9→97.0MiB Whole-process peak191.9→196.5MiB, dominated by startup. Request median2.51→2.44ms.
64,000types,64clients,4,200queries;12GiB cap Five-minute idle919.3→342.9MiB Both4,200/4,200 successful. Whole-process peak964.2→924.8MiB; median15.40→15.07ms.
39.29MiB responses,4clients,36queries Five-minute idle255.9→63.1MiB Tradeoff: peak367.8→576.6MiB, bracketed query CPU6.63→10.88s, observed p95749→1,234ms. Median499→505ms. One trial per allocator.

The full16-process experiment also includes v2.1.1 with/without mimalloc. Both old stress variants still OOM at12GiB; mimalloc is not a replacement for the config-sharing fix. Across all workloads9,120 successful responses matched. Only within-version pairs isolate the allocator; comparing releases also includes dependency/release differences.

These are isolated local synthetic observations, not production benchmarks or a diagnosis of a customer deployment. RSS sampled every100ms can miss brief spikes; cgroup CPU estimates bracket exact burst events using those samples. Small response/stress timing is similar, but the single large-response trial shows a real reason for further validation.

Validation

  • cargo +1.94.1 test --locked --release --package mongodb-agent-common --package mongodb-connector: 301passed,0failed,0ignored, including the two Arc-sharing regressions. Feature-gated MongoDB integration suites are not enabled by this command.
  • cargo +1.94.1 clippy --locked --release --workspace --all-targets -- -D warnings: passed.
  • cargo +1.94.1 build --locked --release --package mongodb-connector: passed; allocator symbols confirmed in the final binary.
  • Final unconditional-allocator binary smoke:12/12 large-schema query responses match the expected4,129bytes/SHA-256; no OOM. This is functional validation, not another performance run.
  • Changed Rust entrypoint passes Rust1.94.1 formatting; git diff --check passes. A repo-wide format check reports pre-existing drift in12unchanged files; all12are byte-identical to main, and no unrelated formatting churn is included.
  • Cargo.lock validation proves all original package versions and dependency edges unchanged, except the intended connector→mimalloc edge and two new allocator packages.

Hosted workflows run normally; their results are not claimed green in advance. Nix/static/cross-target builds, security scans, and full MongoDB integration suites remain to be reviewed. No CI safety bypass or MongoDB/kernel workaround is included.

Why draft / before merge

The lower idle footprint makes this worth evaluating separately from #201, but this is not an unconditional performance win. Before a merge/release recommendation:

  • Repeat/expand large-response trials using representative result sizes and concurrency, with explicit peak-memory, CPU and tail-latency acceptance criteria.
  • Review normal hosted CI, including Nix/static/multi-architecture builds and security scans. This is new C allocator code, so deployment-target build validation matters.
  • Obtain human review; the author cannot approve their own PR.

No merge, deployment, version bump, tag, or release is requested by this PR.

Origin and evidence

Originating bot and full experiment report. Open the MongoDB connector: memory after the burst app artifact there for the four-way tables, individual RSS curves, response hashes, toolchain/source manifests and reproduction instructions. Evidence uses synthetic data only.

@codedmart codedmart self-assigned this Nov 3, 2026
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.

1 participant