Skip to content

Avoid double formatting in mo.output.replace#9909

Merged
mscolnick merged 1 commit into
marimo-team:mainfrom
lxingy3:fix-output-replace-single-format
Jun 29, 2026
Merged

Avoid double formatting in mo.output.replace#9909
mscolnick merged 1 commit into
marimo-team:mainfrom
lxingy3:fix-output-replace-single-format

Conversation

@lxingy3

@lxingy3 lxingy3 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #9681

mo.output.replace(value) was formatting value once for the imperative output list and then again when broadcasting the cell output. This reuses the Html object produced for the output list when sending the notification, so expensive _repr_html_ / __panel__ paths only run once.

A regression test covers a probe object whose _repr_html_ increments a counter.

Tests

  • python -m pytest tests\_runtime\output\test_output.py -q
  • python -m ruff check marimo\_runtime\output\_output.py tests\_runtime\output\test_output.py
  • git diff --check

Review in cubic

@vercel

vercel Bot commented Jun 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Jun 29, 2026 5:47pm

Request Review

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@lxingy3

lxingy3 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@lxingy3 lxingy3 force-pushed the fix-output-replace-single-format branch from 95e3db8 to ff3d9f8 Compare June 25, 2026 06:32
@lxingy3 lxingy3 marked this pull request as ready for review June 25, 2026 06:36
@lxingy3

lxingy3 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased this on current main to pick up the auth test/dependency fix that was already green upstream.

Local checks:

uv run --group test pytest tests/_runtime/output/test_output.py tests/_server/api/test_auth.py -q
uv run --group dev ruff check marimo/_runtime/output/_output.py tests/_runtime/output/test_output.py tests/_server/api/test_auth.py

The PR diff is still limited to the output replacement fix and its regression test.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Reduces the cost of mo.output.replace(value) by avoiding a second formatting pass when broadcasting the updated cell output, targeting expensive _repr_html_ / __panel__ formatting paths.

Changes:

  • Reuse a single formatted Html object in mo.output.replace to prevent duplicate formatter invocation.
  • Add a regression test that verifies _repr_html_ is only called once during mo.output.replace.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
marimo/_runtime/output/_output.py Changes replace() to reuse the formatted output when emitting the output notification.
tests/_runtime/output/test_output.py Adds a probe-based regression test to ensure formatting only occurs once.
Comment on lines 51 to +56
if value is not None:
output.append(formatting.as_html(value))
write_internal(cell_id=ctx.execution_context.cell_id, value=value)
html = formatting.as_html(value)
output.append(html)
write_internal(cell_id=ctx.execution_context.cell_id, value=html)
else:
write_internal(cell_id=ctx.execution_context.cell_id, value=value)
@mscolnick mscolnick added the bug Something isn't working label Jun 29, 2026
@mscolnick mscolnick force-pushed the fix-output-replace-single-format branch from ff3d9f8 to 5ef8dff Compare June 29, 2026 17:46
@mscolnick mscolnick merged commit 7befad3 into marimo-team:main Jun 29, 2026
36 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

3 participants