Skip to content

perf(core): add document-level and block-level caching to pm→markdown serialization#1047

Merged
d3m1d0v merged 4 commits intomainfrom
serializer-perf
Apr 9, 2026
Merged

perf(core): add document-level and block-level caching to pm→markdown serialization#1047
d3m1d0v merged 4 commits intomainfrom
serializer-perf

Conversation

@d3m1d0v
Copy link
Copy Markdown
Member

@d3m1d0v d3m1d0v commented Apr 6, 2026

Summary

Two-level caching in MarkdownSerializer:

  • Document-level: when serialize() is called with the same doc node and equivalent options, returns the cached result without re-serialization
  • Top-level block cache: when the document changes, only modified top-level blocks are re-serialized; unchanged blocks are served from a WeakMap cache

Options are compared using a hybrid approach: reference equality first (===), then field-by-field with RegExp support.

@gravity-ui
Copy link
Copy Markdown

gravity-ui bot commented Apr 6, 2026

Storybook Deployed

@gravity-ui
Copy link
Copy Markdown

gravity-ui bot commented Apr 6, 2026

🎭 Playwright Report

Base automatically changed from upd-serializer2 to main April 7, 2026 12:19
@d3m1d0v d3m1d0v changed the title perf(core): cache serializer result for unchanged documents perf(core): add document-level and block-level caching to pm→markdown serialization Apr 7, 2026
d3m1d0v added 2 commits April 7, 2026 19:29
Repeated serialize() calls with the same document node and equivalent
options now return the cached result without re-serialization.
Options are compared by reference first, then field-by-field
(with RegExp support via source+flags).
When the document changes, only modified top-level blocks are
re-serialized. Unchanged blocks (same node reference) reuse their
cached output. Cache validity also accounts for the preceding block
type, which affects inter-block separators (e.g. triple newline
between consecutive lists of the same type).
@d3m1d0v d3m1d0v marked this pull request as ready for review April 7, 2026 17:10
@d3m1d0v d3m1d0v requested a review from makhnatkin as a code owner April 7, 2026 17:10
@d3m1d0v d3m1d0v merged commit 8fe6fa7 into main Apr 9, 2026
6 of 7 checks passed
@d3m1d0v d3m1d0v deleted the serializer-perf branch April 9, 2026 08:54
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