Skip to content

Profile suite#496

Closed
gabrielbosio wants to merge 15 commits into
feat/heap-profilingfrom
feat/profile-programs
Closed

Profile suite#496
gabrielbosio wants to merge 15 commits into
feat/heap-profilingfrom
feat/profile-programs

Conversation

@gabrielbosio

@gabrielbosio gabrielbosio commented Apr 14, 2026

Copy link
Copy Markdown
Collaborator

Adds a script that runs heap and timing profiling over the following programs:

  • fib_iterative
  • modexp
  • keccak
  • matrix_multiply
  • bitwise_ops

Adapts programs so that we can compile them with different inputs, allowing profiling the same program with different sizes and see how the program scales.

Base branch is the one from #475 but it also cherry-picks #495 for a complete profiling toolkit.

Adds CI benchmark command for all the programs, not only fib_iterative.

@github-actions

Copy link
Copy Markdown

Codex Code Review

  1. High (Security): path traversal enables destructive rm -rf outside /tmp

  2. Low (Potential bug): unchecked compile-time numeric parsing can silently produce wrong values

No other concrete security/bug/performance issues stood out in the PR diff.

let mut r = 0;
let mut i = 0;
while i < b.len() {
r = r * 10 + (b[i] - b'0') as usize;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium – Silent wrong value on non-digit input

b[i] - b'0' doesn't validate the byte is actually '0'..='9'. Since b'k' (107) > b'0' (48) there's no wrap/panic — the subtraction just yields 59 and the wrong iteration count is used silently.

For example, ITERATIONS=1k computes 1*10 + 59 = 69 iterations instead of failing loudly.

This is a const fn evaluated at compile time, so a panic here becomes a compile error with a clear message:

Suggested change
r = r * 10 + (b[i] - b'0') as usize;
assert!(b[i] >= b'0' && b[i] <= b'9');
r = r * 10 + (b[i] - b'0') as usize;

Same issue exists in keccak/src/main.rs, matrix_multiply/src/main.rs, and modular_exp/src/main.rs.

Comment on lines 55 to 57
let mut a = [[0u32; SIZE]; SIZE];
let mut b = [[0u32; SIZE]; SIZE];
let mut result = [[0u32; SIZE]; SIZE];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low – Stack overflow for large SIZE

All three matrices are stack-allocated: SIZE × SIZE × 4 bytes × 3 = SIZE² × 12 bytes. Default SIZE=81 → ~79 KB which is fine, but SIZE=200 → ~480 KB and SIZE=500 → ~3 MB will likely stack-overflow.

Consider a note in the script / usage comment that SIZE values above ~150 risk stack overflow, or cap the default range in profile_suite.sh (current max is 80, which is safe).

@claude

claude Bot commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Review: Profile Suite

Overview: Adds a profiling toolkit — heap + timing profiles across multiple bench programs (fib_iterative, modular_exp, keccak, matrix_multiply, bitwise_ops). Bench programs are migrated from no_std + manual entry point to lambda-vm-syscalls and made configurable via env vars at compile time. The scripts are clean and follow consistent patterns.


Issues

Medium — const fn parse() silently produces wrong values on invalid input (inline)
Non-digit characters (e.g. ITERATIONS=1k) don't panic or error — they silently compute a wrong iteration count because unsigned subtraction doesn't underflow for chars above '0'. Since this is const, an assert!(b[i] >= b'0' && b[i] <= b'9') becomes a compile-time error with a clear message. Same issue in all four bench main.rs files.

Low — Stack overflow risk in matrix_multiply (inline)
Three SIZE×SIZE arrays on the stack. Current default and profiling range (max SIZE=80) is fine, but the risk is invisible to someone who runs build_bench_sizes.sh matrix_multiply SIZE 200.

Low — const fn parse() duplicated 4× across bench programs
The function is identical in every bench program. Since each bench lives in its own Cargo workspace, sharing via a crate path isn't straightforward, but a comment like // keep in sync with sibling bench programs would help avoid silent divergence.


Minor observations

  • suffix_to_steps now passes unknown suffixes through as-is (e.g. "5000") rather than erroring. This is intentional and documented in the comment, but the downstream awk growth-rate section reports "per 1M steps" even when "steps" are actually iteration counts — numbers are correct but the label can be confusing.
  • Script style is consistent and set -euo pipefail is used throughout. The $HEAP && ... pattern is safe because the left operand of && doesn't trigger set -e on failure.

@gabrielbosio
gabrielbosio deleted the branch feat/heap-profiling April 20, 2026 18:15
@gabrielbosio
gabrielbosio deleted the feat/profile-programs branch April 20, 2026 18:15
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