Skip to content

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

Draft
marcoroth wants to merge 19 commits into
mainfrom
arena-reuse
Draft

marcoroth wants to merge 19 commits into
mainfrom
arena-reuse

Conversation

@marcoroth

@marcoroth marcoroth commented Feb 18, 2026

Copy link
Copy Markdown
Owner

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

@github-actions github-actions Bot added parser HTML+ERB parser lexer HTML+ERB lexer ruby Ruby source for the gem and its libraries wasm WebAssembly build and bindings typescript TypeScript source across the javascript/ packages c C source for the core parser, lexer, and AST node @herb-tools/node native Node.js addon node-wasm @herb-tools/node-wasm WebAssembly parser for Node.js c-extension Ruby C extension in ext/ rubygem The herb RubyGem and its packaging rust Rust bindings and the Herb Rust crate cpp C++ source, primarily the WebAssembly bindings browser @herb-tools/browser WebAssembly parser for browsers labels Feb 18, 2026
@marcoroth marcoroth changed the title C: Allow to resue arena beteween parse/lex calls C: Allow to reuse arena between multiple parse/lex calls Feb 18, 2026
@pkg-pr-new

pkg-pr-new Bot commented Feb 18, 2026

Copy link
Copy Markdown
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
Copy Markdown

馃尶 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 @herb-tools/core shared AST nodes, interfaces, and utilities label Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

browser @herb-tools/browser WebAssembly parser for browsers c C source for the core parser, lexer, and AST c-extension Ruby C extension in ext/ core @herb-tools/core shared AST nodes, interfaces, and utilities cpp C++ source, primarily the WebAssembly bindings lexer HTML+ERB lexer node @herb-tools/node native Node.js addon node-wasm @herb-tools/node-wasm WebAssembly parser for Node.js parser HTML+ERB parser ruby Ruby source for the gem and its libraries rubygem The herb RubyGem and its packaging rust Rust bindings and the Herb Rust crate typescript TypeScript source across the javascript/ packages wasm WebAssembly build and bindings

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