Avoid double formatting in mo.output.replace#9909
Merged
mscolnick merged 1 commit intoJun 29, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
mscolnick
approved these changes
Jun 17, 2026
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
95e3db8 to
ff3d9f8
Compare
Contributor
Author
|
Rebased this on current 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.pyThe PR diff is still limited to the output replacement fix and its regression test. |
Contributor
There was a problem hiding this comment.
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
Htmlobject inmo.output.replaceto prevent duplicate formatter invocation. - Add a regression test that verifies
_repr_html_is only called once duringmo.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) |
ff3d9f8 to
5ef8dff
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #9681
mo.output.replace(value)was formattingvalueonce for the imperative output list and then again when broadcasting the cell output. This reuses theHtmlobject 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 -qpython -m ruff check marimo\_runtime\output\_output.py tests\_runtime\output\test_output.pygit diff --check