Skip to content

Commit e6bf28d

Browse files
committed
Fix multiple issues in closure_performance.rs
- Fixed private field access to call_stack by using public execute_closure API - Updated deprecated criterion::black_box to std::hint::black_box - Changed doc comment to regular comment before macro invocation - The benchmark now properly tests call stack operations through the public interface
1 parent 90ac435 commit e6bf28d

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

benches/closure_performance.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
//! This module contains comprehensive benchmarks for measuring closure creation
44
//! and execution performance, memory usage, and optimization effectiveness.
55
6-
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
6+
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
7+
use std::hint::black_box;
78
use script::runtime::closure::{create_closure_heap, Closure, ClosureRuntime};
89
use script::runtime::gc;
910
use script::runtime::Value;
@@ -329,14 +330,14 @@ fn bench_closure_cloning(c: &mut Criterion) {
329330
group.bench_function("call_stack_operations", |b| {
330331
let mut runtime = ClosureRuntime::new();
331332
let closure = Closure::new("test".to_string(), vec!["x".to_string()], HashMap::new());
333+
334+
// Register a simple closure implementation
335+
runtime.register_closure("test".to_string(), |_args| Ok(Value::Null));
332336

333337
b.iter(|| {
334-
// Simulate the call stack push/pop from execute_closure
335-
let stack_depth_before = runtime.call_stack_depth();
336-
runtime.call_stack.push(closure.clone()); // This is what's expensive
337-
let stack_depth_after = runtime.call_stack_depth();
338-
runtime.call_stack.pop();
339-
black_box((stack_depth_before, stack_depth_after));
338+
// Use execute_closure which handles call stack internally
339+
let result = runtime.execute_closure(&closure, &[Value::I32(42)]);
340+
black_box(result);
340341
});
341342
});
342343

@@ -360,7 +361,7 @@ fn create_test_captures(count: usize) -> Vec<(String, Value)> {
360361
.collect()
361362
}
362363

363-
/// Configure benchmark groups
364+
// Configure benchmark groups
364365
criterion_group!(
365366
name = closure_benches;
366367
config = Criterion::default()

0 commit comments

Comments
 (0)