Skip to content

refactor(chat): replace remark with Comark - #1

Draft
onmax wants to merge 10 commits into
mainfrom
spike/comark
Draft

onmax wants to merge 10 commits into
mainfrom
spike/comark

Conversation

@onmax

@onmax onmax commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Summary

chat parses every message with unified/remark, which pulls 71 packages into its production dependencies and needs 333 lines of input guards to stay fast on hostile messages. this is a spike to measure what goes away with Comark. it isn't meant to merge.

this swaps remark for Comark in chat and every adapter, installed from the pkg.pr.new build of comarkdown/comark#529, which reads frontmatter with tinyaml instead of js-yaml. chat drops to 10 production dependencies.

chat parses with comark/core, which leaves out Comark's default plugins, and links text with tinylinkify's linkifyGfm in place of Comark's linkify-it. linkify-it 6 doesn't link www.example.com, which remark-gfm did; tinylinkify/gfm links what remark-gfm links, so www. addresses keep working and bare domains like hackmd.io/x stay plain text. it's installed from the pkg.pr.new build of tiny v0.1.2 until that's on npm.

added removed net
source 1,612 1,930 −318
tests 3,354 5,159 −1,805

parsing and rendering get 5.5 to 17 times faster. median of 5 rounds per call, Apple M4, Node 26.13. medium is a 652-character LLM-style reply. these timings are from the earlier Comark build and haven't been rerun on this one.

operation remark Comark speedup
parseMarkdown medium 307.1 µs 21.4 µs 14.4x
stringifyMarkdown medium 104.7 µs 18.0 µs 5.8x
teams fromMarkdown medium 325.6 µs 27.3 µs 11.9x
discord fromMarkdown medium 315.8 µs 37.8 µs 8.3x
telegram fromMarkdown medium 415.4 µs 29.8 µs 13.9x
slack parseIncoming mrkdwn 147.5 µs 13.2 µs 11.2x
streaming render, 12-char chunks 425.8 µs 44.9 µs 9.5x

bundles still grow, by 5% to 13% gzip. the duplicate entities table that made up most of it is gone upstream (serkodev/markdown-exit#40, comarkdown/comark#549). what's left is Comark's own layer on top of markdown-exit, linkify-it, and tinyaml (2.5 KiB gzip, which Comark's stringifier imports for YAML props). esbuild 0.28, minified ESM, KiB minified / gzip.

entry remark Comark gzip change
parser libraries only 158.8 / 48.4 151.8 / 52.7 +9%
chat, whole package 266.6 / 77.2 272.3 / 87.0 +13%
@chat-adapter/telegram 279.8 / 82.8 284.6 / 91.8 +11%
@chat-adapter/slack 695.1 / 192.6 700.3 / 201.7 +5%

Test plan

pnpm knip, pnpm check, and turbo typecheck test pass for every package (89 tasks), integration tests included. node scripts/bench-markdown.mjs <repo-root> <label> reproduces the timings.

Checklist

  • All commits are signed and verified
  • All commits are signed off for the DCO (git commit -s)
  • pnpm validate passes
  • Changeset added (or N/A — see CONTRIBUTING.md)
  • Documentation updated (or N/A)

Reviewed with sol-loop: 1 round with gpt-6.1-sol on xhigh. Sol verdict: approved

@onmax onmax changed the title spike: replace remark with Comark replace remark with Comark Oct 31, 2026
@onmax onmax changed the title replace remark with Comark refactor(chat): replace remark with Comark Nov 2, 2026
onmax added 7 commits November 9, 2026 10:40
Drop async and await the port added to tests that never wait, a
one-caller GitLab wrapper, Twilio's structuredClone (walkAst returns a
copy), and a chat test that re-tested the plain nested-list path after
the HTML branch went away. Rename tests that only check serialization,
and keep the benchmark script out of knip.

Signed-off-by: onmax <maximogarciamtnez@gmail.com>
Comark now ships linkify as a default plugin, and chat turns default
plugins off, so it registers linkify() itself. Its defaults leave bare
domains like hackmd.io unlinked, as remark-gfm does.
onmax added 3 commits November 9, 2026 10:47
…lose

chat turns off Comark's default plugins, but importing the root comark
entry still bundled them. comark/core and comark/auto-close leave them out.
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