Skip to content

Feature-gated allocation counter + alloc-budget test#79

Merged
joaquinbejar merged 1 commit intomainfrom
issue-58-alloc-counter
Apr 25, 2026
Merged

Feature-gated allocation counter + alloc-budget test#79
joaquinbejar merged 1 commit intomainfrom
issue-58-alloc-counter

Conversation

@joaquinbejar
Copy link
Copy Markdown
Owner

Closes #58. Adds CountingAllocator + AllocSnapshot behind alloc-counters feature, alloc_count bench reporting allocs_per_op + bytes_alloc/op, and tests/alloc_budget.rs asserting allocs/op < 10 over 10k mixed ops. Library rlib does not install a global allocator. mod utils is now pub. BENCH.md gains Allocation profile section.

Wraps any inner GlobalAlloc and tracks four AtomicU64 counters
(allocs / deallocs / bytes_allocated / bytes_deallocated). Bench /
test binaries opt in via:

    use orderbook_rs::CountingAllocator;
    use std::alloc::System;
    #[global_allocator]
    static A: CountingAllocator<System> = CountingAllocator::new(System);

The library rlib does not install a global allocator. The wrapper
exists so bench / budget-test binaries can measure hot-path
allocation without forcing a global choice.

New bench at benches/order_book/alloc_count.rs reports allocs_per_op
+ bytes_alloc/op for the mixed 70/20/10 workload (200k warmup +
1M measured) and writes a markdown summary to
target/alloc-counters/. New integration test at
tests/alloc_budget.rs (its own [[test]] binary, gated on
alloc-counters) asserts allocs/op < 10 over 10 000 mixed ops as a
CI regression guard.

mod utils is now pub mod utils so the new types are reachable via
the canonical orderbook_rs::utils path. counting_allocator carries a
documented #[allow(unsafe_code)] exception confined to the
GlobalAlloc trait boundary.

BENCH.md gains an Allocation profile section. CHANGELOG and lib.rs
updated.

Closes #58.
@joaquinbejar joaquinbejar merged commit 7aaa560 into main Apr 25, 2026
11 of 13 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.

Feature-gated hot-path allocation counter + alloc-budget test

1 participant