Skip to content

Dk inspect algebra unboxed worklist - #15946

Merged
josevalim merged 3 commits into
elixir-lang:mainfrom
dkuku:dk_inspect_algebra_unboxed_worklist
Sep 26, 2026
Merged

josevalim merged 3 commits into
elixir-lang:mainfrom
dkuku:dk_inspect_algebra_unboxed_worklist

Conversation

@dkuku

@dkuku dkuku commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Carry the current worklist entry in registers in Inspect.Algebra.fits? and Inspect.Algebra.format instead of boxing it back onto the {indent, mode, doc} entry list on every step.

  • Unwrapping intermediate nodes (doc_nest, doc_color, doc_force, doc_fits) now allocates nothing.
  • doc_cons(x, y) only allocates one entry (for y), passing x immediately in registers.
  • The k > w and b? guard remains centralized in fits?/4.

Benchmarks (Benchee, OTP 29)

  • Memory: 39% – 53% less memory allocated across AST and data formatting (e.g. 5.87 MB → 2.74 MB on Code AST).
  • Execution time: 1.08x – 1.37x faster.

Assisted-by: Antigravity:Gemini 3.8 Flash

dkuku and others added 3 commits September 26, 2026 19:10
fits?/4 and format/4 walked the document through a list of {i, mode, doc}
entries. Every step popped one entry and pushed the rewritten one back,
allocating a 4-word tuple plus a 2-word cons cell for a value consumed
on the very next iteration.

fits?/7 and format/7 now take the head entry unboxed in registers and only
box what stays on the list, so unwrapping intermediate nodes allocates
nothing and a cons allocates one entry instead of two.

The k > w check stays in fits?/4 only: every clause that grows k hands
over to fits?/4, ensuring the guard cannot be skipped.

Assisted-by: Antigravity:Gemini 3.8 Flash
@josevalim
josevalim merged commit 4239c5d into elixir-lang:main Sep 26, 2026
15 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants