Skip to content

Heap-allocated HybridBigInt — macOS stack overflow fix #500

@gHashTag

Description

@gHashTag

Problem

macOS gives background threads only 512 KB stack. HybridBigInt + VSAVM allocate ~460 KB on stack in single instance.

Changes

src/hybrid.zig

  • Move unpacked_cache from 59KB stack array [MAX_TRITS]Trit to 8-byte heap pointer (?[]Trit)
  • Add allocator field for heap operations
  • Add deinit() method for cleanup
  • Update ALL methods to accept allocator parameter and ensure heap allocation

src/vsa/core.zig

  • Update bundleN() to allocate 115KB accumulator on heap
  • Update all VSA operations to pass allocator parameter
  • Use safe access patterns for unpacked_cache

Metrics

Metric Before After
HybridBigInt × 1 69.2 KB 11.6 KB
HybridBigInt × 4 (VSAVM registers) 276.8 KB 46.2 KB
bundleN() accum 115.3 KB 0 KB (heap)
Total VSAVM ~460 KB ~70 KB

macOS thread stack = 512 KB → 7.3× safety margin (370 KB free)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions