Skip to content

[LQP Meta] Pretty printer optimizations#219

Open
nystrom wants to merge 1 commit intomainfrom
nn-meta-pretty-opts
Open

[LQP Meta] Pretty printer optimizations#219
nystrom wants to merge 1 commit intomainfrom
nn-meta-pretty-opts

Conversation

@nystrom
Copy link
Contributor

@nystrom nystrom commented Feb 25, 2026

Summary

Optimize the generated pretty printer code by:

  1. Beta-reducing lambda calls inline: When a Call(Lambda(...), args) pattern is detected, the codegen now assigns arguments to parameters and evaluates the lambda body directly, eliminating redundant closures in the generated code.

  2. Merging consecutive write_io literals: In Seq expressions, consecutive write_io calls with string literals are merged into a single write_io call, reducing function call overhead.

Changes

  • meta/src/meta/codegen_base.py: Added beta-reduction support (_enter_beta_body/_exit_beta_body hooks), _extract_write_io_literal, _flush_write_io_literals, and updated _generate_Seq to merge consecutive writes.
  • meta/src/meta/codegen_go.py: Added lambda return type tracking for correct type hints during beta reduction.
  • sdks/go/src/pretty.go, sdks/julia/.../pretty.jl, sdks/python/.../pretty.py: Regenerated with the new optimizations, resulting in a net reduction of ~1,245 lines.

@nystrom nystrom changed the title Eliminate redundant closures, merge consecutive writes in pretty printer [LQP Meta] Pretty printer optimizations Feb 25, 2026
@nystrom nystrom requested a review from comnik February 25, 2026 15:30
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.

2 participants