$ the-wire · showcase
Inspect.Algebra stops allocating on every break
By RepoJournal · Filed · About Elixir & Phoenix · Composed from the cited sources · methodology
Two changes from dkuku remove per-step heap allocation from Elixir's Inspect.Algebra formatter, trading runtime binary construction for register-passed values and compile-time literals.
Dk inspect algebra unboxed worklist elixir-lang/elixir
Inspect.Algebra.fits? and format now carry the current worklist entry in registers rather than re-boxing it onto the {indent, mode, doc} entry list at every step. Unwrapping doc_nest, doc_color, doc_force, and doc_fits allocates nothing, doc_cons allocates only the entry for y, and the k > w and b? guard stays centralized in fits?/4.
Cache common indentation in Inspect.Algebra elixir-lang/elixir
indent(i) previously built two intermediate binaries per break, a :binary.copy and an @newline concatenation, dropping immediate garbage on the process heap. Precalculating collapsed newlines for 0..2 and inlining @newline into the binary builder removes that allocation; widths up to 64 became compile-time literals because :binary.copy/2 pays O(N) allocation and copying cost.
Cache common indentation in Inspect.Algebra (#15947) elixir-lang/elixir
The merged commit lands the indentation caching: newlines are inlined at break call sites and function heads are generated for common indentation widths, so the common path returns literals instead of calling into :binary.copy/2.