Skip to content

🔴 [Critical] MinimalEvm: HashMap-based memory is extremely inefficient #851

@roninjin10

Description

@roninjin10

Summary

The MinimalEvm Frame uses AutoHashMap(u32, u8) for EVM memory, requiring a hash lookup for every single byte access. This is orders of magnitude slower than necessary.

Location

mini/src/frame.zig:50-51

Current Code

memory: std.AutoHashMap(u32, u8),
memory_size: u32,

Problem

  • Each byte read/write requires hash computation and lookup
  • No cache locality - bytes are scattered in memory
  • Memory expansion requires inserting each byte individually
  • Significantly slower than the performance EVM's ArrayList approach

Impact

  • Poor performance for memory-intensive operations (MLOAD, MSTORE, MCOPY, KECCAK256)
  • Increased memory overhead (HashMap metadata per byte)
  • Makes the "mini" EVM unsuitable even for simple benchmarking

Recommended Fix

Replace with std.ArrayList(u8) like the performance EVM:

memory: std.ArrayList(u8),

This provides:

  • O(1) indexed access
  • Contiguous memory for cache efficiency
  • Efficient bulk operations

Note: This issue was created by Claude AI assistant during code review, not @roninjin10 or @fucory

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions