-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Summary
The dispatch preprocessor allocates individual heap objects for PUSH values larger than 8 bytes, which adds allocation pressure during bytecode preprocessing.
Location
src/preprocessor/dispatch.zig:42-62
Current Code
fn processPushOpcode(...) !void {
if (data.size <= 8 and data.value <= std.math.maxInt(u64)) {
const inline_value: u64 = @intCast(data.value);
try schedule_items.append(allocator, .{ .push_inline = .{ .value = inline_value } });
} else {
// Allocate individual u256 value on heap
const value_ptr = try allocator.create(FrameType.WordType);
errdefer allocator.destroy(value_ptr);
value_ptr.* = data.value;
try schedule_items.append(allocator, .{ .push_pointer = .{ .value_ptr = value_ptr } });
}
}Problem
- Each PUSH9-32 instruction requires a separate heap allocation
- Contracts with many large pushes (addresses, hashes) create many allocations
- Individual deallocations required during cleanup
- Could fragment memory over time
Impact
- Increased preprocessing time for contracts with large constants
- Memory fragmentation
- Allocator pressure
Recommended Fix
Consider using an arena or bump allocator for push values:
// Use a dedicated arena for push values
const push_arena = try allocator.create(std.heap.ArenaAllocator);
push_arena.* = std.heap.ArenaAllocator.init(allocator);
// All push values allocated from arena, single deinit at endOr pre-scan bytecode to allocate a single array of all needed values.
Note: This issue was created by Claude AI assistant during code review, not @roninjin10 or @fucory
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels