Skip to content

Developer playground: compare Lambda before and after optimization - #8636

Open
fhammerschmidt wants to merge 3 commits into
masterfrom
playground-lambda-diff
Open

fhammerschmidt wants to merge 3 commits into
masterfrom
playground-lambda-diff

Conversation

@fhammerschmidt

@fhammerschmidt fhammerschmidt commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Add Before, After, and Diff views to the developer playground's Lambda tab. Playground API v9 exposes lambda_optimized from compileWithDebug after the whole-term Lambda passes and before export grouping and JavaScript lowering. Regular compilation does not capture debug output; older compiler bundles retain an availability notice.

Keep the Lambda view mounted and cache the latest rendered comparison by its printed inputs, including line alignment, inline highlights, and context sections. Switching tabs or recompiling identical dumps reuses the diff DOM. Collapsed context renders only when expanded, and unchanged regions retain their expansion state across edits.

Strip shared edges before the line comparison, count those edges once in the output budget, and omit empty visible sections. Token alignment prioritizes shared atoms over punctuation. Preflight all candidate work in a changed block and skip the whole block when it cannot fit the remaining global budget, preserving capacity for later small changes. Actual work on unchosen candidates remains counted so the overall bound still holds.

Validation:

  • Native compiler, Rewatch, runtime, Belt, and browser compiler builds pass.
  • Full compiler suites pass: 270 unit tests, 604 runtime tests, all 41 build fixtures, and 744 documentation examples.
  • All 33 developer playground tests pass, including 22 Lambda algorithm/rendering tests, and the playground bundle tests cover API v9 optimized output and regular compilation.
  • Production Vite build, repository-wide OCaml/ReScript/JavaScript/Rust formatting, and changelog validation pass.
  • Mounted DOM checks with a DOM emulator verify lazy context rendering, DOM reuse, expansion across changed inputs, and toggling. Chromium cannot launch in this macOS environment because system appearance resources are unavailable, so browser layout and scrolling remain unverified here.

required

let compile (output_prefix : string) export_idents hoisted (lam : Lambda.t) =
let compile ?on_optimized_lambda (output_prefix : string) export_idents hoisted

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems I cannot extract optimized lambda for the playground without this addition

@codecov

codecov Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.51%. Comparing base (7957c10) to head (e33b965).

Files with missing lines Patch % Lines
compiler/core/lam_compile_main.ml 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8636      +/-   ##
==========================================
- Coverage   80.51%   80.51%   -0.01%     
==========================================
  Files         447      447              
  Lines       61060    61062       +2     
==========================================
+ Hits        49162    49163       +1     
- Misses      11898    11899       +1     
Files with missing lines Coverage Δ
compiler/core/lam_compile_main.ml 89.47% <0.00%> (-0.33%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8636

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@8636

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8636

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8636

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8636

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8636

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8636

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8636

commit: e33b965

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

@fhammerschmidt
fhammerschmidt marked this pull request as ready for review September 9, 2026 21:57
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T13:26:25.416528Z 1be49a8 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@fhammerschmidt

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 1be49a87d6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cknitt

cknitt commented Oct 13, 2026

Copy link
Copy Markdown
Member

Review notes (no wrong-diff bugs found; mostly performance):

Performance

  1. LambdaView.res:78: the diff is recomputed on every compile. LambdaView is rebuilt per compile result, so the Lazy cache only lives for one render, and LambdaInlineDiff.highlight / LambdaDiff.sections aren't cached at all. With the Diff subtab open, each keystroke reruns the line diff (up to 1M cells) and the token diff (up to 250k cells) and rebuilds the diff DOM. Switching Before → Diff → Before → Diff redoes the work too.
  2. LambdaView.res:67: collapsed sections still render every hidden line. renderLines runs eagerly inside each closed <details>, so a 10k-line dump with a one-line change still creates ~10k line spans (×4 children). Rendering on toggle would avoid that.
  3. LambdaDiff.res:49: the maxLines check uses the untrimmed n + m. Two 10,001-line dumps that differ in one line trim to a 1×1 middle but still show "exceeds the diff work limit", which contradicts the comment and the test.
  4. LambdaInlineDiff.res:172: the shared token budget is charged for every candidate pair in a block, including pairs that are never chosen. One early large block (e.g. 16×16 lines of ~100 tokens) can drain the 250k budget, and every later block falls back to whole-line highlighting based on position, not similarity.

Behaviour
5. LambdaInlineDiff.res:711: the token LCS maximizes all matched tokens, punctuation included, but pairing uses the count of shared atoms. An alignment that matches (/) instead of atoms can undercount shared and reject similar pairs via shared*2 < largest.
6. Main.res:1335: because LambdaView is replaced on every compile, opened "Show N unchanged lines" sections collapse again and the scroll position jumps after each edit.
7. LambdaDiff.res:154: sections emits Visible([]) before a leading unchanged run (head === start) and after a trailing one (tail === end_), which renders empty <pre class="lambda-diff-block"> elements. The test's flatMap check doesn't catch it.

Nit
8. package.json:12: stray double space before scripts/lambda-diff.test.mjs.

Items 1, 2 and 6 share one fix: keep the view and its diff results alive across compiles, keyed on the input text, and render collapsed sections only when opened.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RrJ4XshH5etfH87fRThk2B

… including diffs

Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
Keep the Lambda view mounted, cache its rendered comparison by input text, and render collapsed context only when expanded. Preserve expansion for unchanged regions across edits.

Count shared edges once in the line budget, prioritize atoms in token alignment, and admit whole changed blocks before charging the shared token budget. Cover the algorithm and rendering regressions, and document the API v9 capture boundary.

Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
@fhammerschmidt fhammerschmidt changed the title Developer playground: Add lambda views before and after optimisation,… Developer playground: compare Lambda before and after optimization Oct 14, 2026

This branch has not been deployed

No deployments
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