Skip to content

refactor(ir): introduce VariableLookup for lightweight variable resolution#130

Open
erickcestari wants to merge 2 commits intodergoegge:masterfrom
erickcestari:improve-performance-input-mutator
Open

refactor(ir): introduce VariableLookup for lightweight variable resolution#130
erickcestari wants to merge 2 commits intodergoegge:masterfrom
erickcestari:improve-performance-input-mutator

Conversation

@erickcestari
Copy link
Contributor

@erickcestari erickcestari commented Mar 2, 2026

This reduces overhead in mutators that only require variable type and scope information, avoiding full program validation/building.

These changes optimize the inputMutator by avoiding validating the full program only to get variable lookups.

fuzzamoto-comparison

These are the results of running fuzzamoto for five hours:

+1.58% total exec
+1.31% coverage
+5.20% corpus
−1.96% stability

A naive benchmark shows that it is 6 times faster to use the variableLookup instead of ProgramBuilder.

program_builder_100k time: [7.0090 ms 7.0274 ms 7.0463 ms]
variable_lookup_100k time: [1.2774 ms 1.2834 ms 1.2907 ms]

use criterion::{Criterion, black_box, criterion_group, criterion_main};
use fuzzamoto_ir::{Operation, Program, ProgramBuilder, ProgramContext, VariableLookup};

fn create_test_program(num_instructions: usize) -> Program {
    let context = ProgramContext {
        num_nodes: 2,
        num_connections: 4,
        timestamp: 1_700_000_000,
    };

    let mut builder = ProgramBuilder::new(context);

    for i in 0..num_instructions {
        match i % 10 {
            0 => { builder.force_append(vec![], &Operation::LoadBytes(vec![0u8; 32])); }
            1 => { builder.force_append(vec![], &Operation::LoadAmount(1000)); }
            2 => { builder.force_append(vec![], &Operation::LoadTime(1_700_000_000)); }
            3 => { builder.force_append(vec![], &Operation::LoadNode(0)); }
            4 => { builder.force_append(vec![], &Operation::LoadConnection(0)); }
            5 => { builder.force_append(vec![], &Operation::LoadSize(100)); }
            6 => { builder.force_append(vec![], &Operation::LoadTxVersion(2)); }
            7 => { builder.force_append(vec![], &Operation::LoadLockTime(0)); }
            8 => { builder.force_append(vec![], &Operation::LoadSequence(0xffffffff)); }
            _ => { builder.force_append(vec![], &Operation::LoadBlockHeight(100)); }
        }
    }

    builder.finalize().expect("Program should be valid")
}

fn bench_large_program(c: &mut Criterion) {
    let program = create_test_program(100_000);

    c.bench_function("program_builder_100k", |b| {
        b.iter(|| {
            let program_upto = Program::unchecked_new(
                program.context.clone(),
                program.instructions[..100_000].to_vec(),
            );
            let builder = ProgramBuilder::from_program(program_upto).unwrap();
            black_box(builder.variable_count())
        })
    });

    c.bench_function("variable_lookup_100k", |b| {
        b.iter(|| {
            let lookup = VariableLookup::from_instructions(&program.instructions[..100_000]);
            black_box(lookup.variable_count())
        })
    });
}

criterion_group!(benches, bench_large_program);
criterion_main!(benches);

@erickcestari erickcestari force-pushed the improve-performance-input-mutator branch from f978cf1 to c8d0efb Compare March 2, 2026 14:47
…ution

This reduces overhead in mutators that only require variable type and
scope information, avoiding full program validation/building.
@erickcestari erickcestari force-pushed the improve-performance-input-mutator branch from c8d0efb to 0743f5e Compare March 2, 2026 22:44
@dergoegge
Copy link
Owner

Awesome, thank you! Would you mind adding the benchmarking tests as well?

@erickcestari
Copy link
Contributor Author

Awesome, thank you! Would you mind adding the benchmarking tests as well?

Yes, I'll add it soon!

@erickcestari
Copy link
Contributor Author

Awesome, thank you! Would you mind adding the benchmarking tests as well?

Added!

…ookup

 This adds a benchmark file comparing ProgramBuilder::from_program against the new lightweight VariableLookup on 100k instructions, along with the criterion dev-dependency.
@erickcestari erickcestari force-pushed the improve-performance-input-mutator branch from dec7eca to d65a2fc Compare March 9, 2026 12:59
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.

2 participants