Skip to content

C: Allow to reuse arena between multiple parse/lex calls#1203

Draft
marcoroth wants to merge 19 commits intomainfrom
arena-reuse
Draft

C: Allow to reuse arena between multiple parse/lex calls#1203
marcoroth wants to merge 19 commits intomainfrom
arena-reuse

Conversation

@marcoroth
Copy link
Owner

@marcoroth marcoroth commented Feb 18, 2026

Depends on #726 to be merged first

This pull request adds the ability to reuse an arena allocator across multiple parse and lex calls, reducing memory allocation overhead for batch processing scenarios.

Ruby API

arena = Herb::Arena.new
arena = Herb::Arena.new(size: 1024 * 1024)

result = Herb.parse(source, arena: arena)
result = Herb.lex(source, arena: arena)

arena.position
arena.capacity
arena.reset
arena.stats

JavaScript API (Node.js, Browser, Node-wasm)

const arena = Herb.createArena()
const arena = Herb.createArena({ size: 1024 * 1024 })

const result = Herb.parse(source, { arena })
const result = Herb.lex(source, { arena })

arena.position
arena.capacity
arena.reset()
arena.free()

Example: Batch Processing

const arena = Herb.createArena()

for (const file of files) {
  const result = Herb.parse(file.content, { arena })
  arena.reset()
}

arena.free()

Resolves #1202

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 18, 2026

npx https://pkg.pr.new/@herb-tools/formatter@1203
npx https://pkg.pr.new/@herb-tools/language-server@1203
npx https://pkg.pr.new/@herb-tools/linter@1203

commit: a932d7d

@github-actions
Copy link

🌿 Interactive Playground and Documentation Preview

A preview deployment has been built for this pull request. Try out the changes live in the interactive playground:


🌱 Grown from commit a932d7d

@github-actions github-actions bot added the core label Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C: Allow Arena to be reused across multiple Herb.parse calls

2 participants