Profile suite#496
Conversation
Codex Code Review
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; |
There was a problem hiding this comment.
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:
| 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.
| let mut a = [[0u32; SIZE]; SIZE]; | ||
| let mut b = [[0u32; SIZE]; SIZE]; | ||
| let mut result = [[0u32; SIZE]; SIZE]; |
There was a problem hiding this comment.
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).
Review: Profile SuiteOverview: Adds a profiling toolkit — heap + timing profiles across multiple bench programs ( IssuesMedium — Low — Stack overflow risk in Low — Minor observations
|
Adds a script that runs heap and timing profiling over the following programs:
fib_iterativemodexpkeccakmatrix_multiplybitwise_opsAdapts 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.