Skip to content

add arena allocator for string allocations#412

Merged
cs01 merged 2 commits intomainfrom
arena-allocator-impl
Mar 16, 2026
Merged

add arena allocator for string allocations#412
cs01 merged 2 commits intomainfrom
arena-allocator-impl

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Mar 16, 2026

Summary

  • Replaces GC_malloc_atomic with bump-pointer arena allocation (cs_arena_alloc) for all temporary string allocations across codegen
  • Arena blocks are backed by Boehm GC (GC_malloc for metadata, GC_malloc_atomic for data), so no memory leaks — GC still manages block lifetime
  • 1MB arena blocks with 8-byte aligned bump pointer — faster than individual GC_malloc_atomic calls for string-heavy workloads

What changed

  • New c_bridges/arena-bridge.c — bump-pointer arena allocator (50 lines)
  • Converted ~45 GC_malloc_atomiccs_arena_alloc calls across: string concat, substr, trim, repeat, pad, replace, case conversion, charAt, split, number-to-string, path ops, date formatting, JSON stringify, process.cwd, os.hostname, String.fromCharCode, regex match extraction, for-of string iteration
  • Non-string allocations (array data buffers, Uint8Array, crypto, file I/O, class instances) remain on Boehm GC
  • Build system: arena-bridge added to build-vendor.sh, compiler linkers, CI, and cross-compile SDK

Test plan

  • npm run verify:quick passes (742 tests + self-hosting stage 0+1)

🤖 Generated with Claude Code

@cs01 cs01 merged commit 09e347a into main Mar 16, 2026
12 checks passed
@cs01 cs01 deleted the arena-allocator-impl branch March 16, 2026 22:34
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.

1 participant