Skip to content

perf(svelte): reuse incremental parsing in streams - #396

Open
onmax wants to merge 3 commits into
comarkdown:mainfrom
onmax:fix/react-svelte-incremental-streaming
Open

perf(svelte): reuse incremental parsing in streams#396
onmax wants to merge 3 commits into
comarkdown:mainfrom
onmax:fix/react-svelte-incremental-streaming

Conversation

@onmax

@onmax onmax commented Sep 5, 2026

Copy link
Copy Markdown

What

Keep a serialized parser in Svelte streaming components so each update reuses completed blocks. Reset it when parser settings change and parse the full source when streaming ends. Use a full parse for heading tails and reference definitions to preserve IDs and links.

Why

Svelte currently parses the entire source on each update, as discussed in #135. Also clear stale frontmatter when a stream switches documents. Fix the Syntax playground's value prop so it renders the example.

Related #397.

Description GitHub
Before Svelte parses the completed prefix again on append. Source
After Svelte parses only the open tail and parses the full source when streaming ends. Source

Parser timings for the shared React/Svelte call pattern, using the published PR code:

Stream Final size Before After
100 paragraph updates 6.7 kB 172 ms 26 ms
300 paragraph updates 20.3 kB 752 ms 84 ms
600 paragraph updates 40.7 kB 2,467 ms 224 ms
300 heading + paragraph updates 25.0 kB 947 ms 808 ms

@onmax
onmax requested a review from farnabaz as a code owner September 5, 2026 10:02
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coldtea-pr-lens

coldtea-pr-lens Bot commented Sep 5, 2026

Copy link
Copy Markdown

◈ PR Lens

🟢 +1 new · 🟠 ~5 changed · 🔴 -0 removed · 1 flow · 13 files · commit e49a6a4


Architecture

Architecture diagram for comarkdown/comark at e49a6a4

6 components touched across 2 lanes.

Open full size


Inside the changed components — 2 views

Component view — Svelte Adapter

Internal modules in @⁠comark/svelte managing reactive component rendering and serialized streaming parse execution.

Architecture view of Component view — Svelte Adapter in comarkdown/comark

Component view — Core Parser & Streaming

Core engine modules handling token processing, frontmatter resetting, and streaming AST node reuse guards.

Architecture view of Component view — Core Parser & Streaming in comarkdown/comark

Data flow

Data flow diagram for comarkdown/comark at e49a6a4

Streaming Markdown Parse in Svelte

Open full size


Drill down
UI Framework Adapters — 3 components
🟡 CHANGED Svelte 5 Renderer

Svelte 5 component adapter that manages reactive parsing lifecycles and serializes async parser calls.

🟡 CHANGED Svelte Markdown Components

Markdown.svelte and MarkdownAsync.svelte components deriving memoized parsers and managing stream effects.

🟢 NEW Component Parser Serializer

Serializes async parser execution over a Promise queue while propagating plugin rejections to Svelte error boundaries.

Core Engine — 3 components
🟡 CHANGED Core Parser

Creates Markdown parsers and coordinates incremental streaming reuse, frontmatter resets, and plugin pipelines.

🟡 CHANGED Token-to-AST Processor

Converts Markdown tokens to AST nodes, omitting reference definition tokens from rendered output.

🟡 CHANGED Bundle Size Suite

Bundle size test suite tracking package footprint snapshots including the Svelte adapter.


View

  • Architecture lens
  • Data flow lens
  • Expand every detail
  • Show unchanged neighbours

Tip

The CLI's render picks up .github/pr-lens.yml automatically and applies your corrections (renames, exclusions, lane pins) at draw time.

🪧 More tips
  • Run PR Lens on your own machine: npx skills add coldteadotai/pr-lens installs the agent skill. Then tell your coding agent: "Diagram the change you just made with PR Lens and attach it to the pull request."
  • Draw a diff before it is even a pull request: npx @coldtea/pr-lens-cli analyze --base origin/main reads the diff with your own model key, and npx @coldtea/pr-lens-cli render .pr-lens/graph.json draws the same lenses on your machine.
  • The boxes under View are live. Tick Architecture lens or Data flow lens to choose which diagrams appear, or Expand every detail to open every drill-down at once. The comment redraws in place a few seconds later.
  • Show unchanged neighbours lists the components this change did not touch alongside the ones it did, so the drill-down shows what the changed code sits next to.
  • GitHub will not let you zoom an image in a comment. The link under each diagram opens it full size on a page of its own, where you can.
  • Would you rather run it from CI on a key of your own? Add .github/workflows/pr-lens.yml with coldteadotai/pr-lens/packages/action@v0 and a model key in your repository secrets, say GEMINI_API_KEY. The Action asks Gemini by default, or OpenAI and any endpoint speaking /chat/completions through its provider input.
  • PR Lens is free for open source. A star on the repository is what keeps it going.
  • Push a new commit and the whole comment re-renders for the new head. An older run never overwrites a newer one, so a slow render cannot put a stale diagram back.
  • The diagrams follow your GitHub theme, so dark mode gets the dark render and light mode the light one, and the moving dots show this pull request's data in motion.

◈ Rendered by PR Lens · crafted with ❤️ by the Coldtea team · Come say hi on Discord

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Documentation previews

Previews are disabled for pull requests from forks.
A maintainer can add the preview:enabled label to enable them.

@vercel

vercel Bot commented Sep 5, 2026

Copy link
Copy Markdown

@onmax is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@onmax onmax changed the title perf: reuse incremental parsing in React and Svelte streams perf(svelte): reuse incremental parsing in streams Sep 5, 2026
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.

1 participant