Skip to content

Enhance mem_usage_benches to more precisely measure peak memory usage #69

Description

@ounsworth

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionThis will involve some community discussion to choose the right designenhancementNew feature or requesthelp wantedCould be picked up by anyone in the communityresearchThis involves some open-ended research

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions