Enhance mem_usage_benches to more precisely measure peak memory usage

Open
#69 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
rust
Domain
performance

Research direction

Start by locating the mem_usage_benches entry point and reviewing how its main function is run under Valgrind. Investigate how to isolate the stack and heap usage of sign_mu_deterministic from setup, constants, and print! overhead. Done means the benchmark reports a more precise peak memory measurement for the signing operation.

Written by the indexing model from the issue text.

Description

discussion enhancement help wanted research

Currently, the memory usage benchmarks are structured like this:

fn main() {
    bench_mldsa87_lowmemory_sign()
}

fn bench_mldsa87_lowmemory_sign() {
    use bouncycastle::mldsa_lowmemory::{MLDSA87, MLDSA87_SK_LEN, MLDSA87PrivateKey, MLDSATrait};

    eprintln!("MLDSA87_lowmemory/Sign");

    let sk = MLDSA87PrivateKey::from_bytes(&[
        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
        0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D,
        0x1E, 0x1F,
    ])
    .unwrap();

    let msg = b"The quick brown fox jumped over the lazy dog";

    let mu = MLDSA87::compute_mu_from_sk(&sk, msg, None).unwrap();
    let sig = MLDSA87::sign_mu_deterministic(&sk, &mu, [0u8; 32]).unwrap();
    print!("{:x?}", sig);
}

Then we run this main within valgrind to measure its peak memory usage.

The problem with this approach is that we are also measuring memory usage of main(), the seed and msg constants, and the two print! macros. (the prints, I think, are required to force the compiler not to elide the actual operations) For some algorithms like sha3, these overheads It would be more ideal to measure only the stack / heap memory usage of the ::signmu_deterministic(..), but I have no idea how to do this. Needs some research.

Dominant language
Rust
Stars
25
Forks
18
Avg merge
16h 38m
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bcgit/bc-rust

All issues in bcgit/bc-rust

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.