Skip to content

perf(plugins): optimize highlight to use codeToTokens fast path to skip hast intermediary#170

Merged
farnabaz merged 3 commits into
mainfrom
perf/highlight-plugin
Apr 29, 2026
Merged

perf(plugins): optimize highlight to use codeToTokens fast path to skip hast intermediary#170
farnabaz merged 3 commits into
mainfrom
perf/highlight-plugin

Conversation

@arashsheyda
Copy link
Copy Markdown
Collaborator

@arashsheyda arashsheyda commented Apr 28, 2026

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

this PR optimizes the highlight plugin further by using shiki's codeToTokens API directly instead of codeToHast when no transformers are configured. this skips the entire hast tree construction and the subsequent hast => ComarkNode conversion, building ComarkNodes directly from the flat token array in a single pass

Before After
Screenshot 2026-04-28 at 11 43 52 AM Screenshot 2026-04-28 at 11 45 49 AM

📝 Checklist

  • I have linked an issue or discussion.
  • I have run pnpm verify and it passes.
  • I have updated the documentation accordingly.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 28, 2026

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

Project Deployment Actions Updated (UTC)
comark Ready Ready Preview Apr 28, 2026 5:57pm
comark-json-render Ready Ready Preview Apr 28, 2026 5:57pm
comark-nextjs Ready Ready Preview Apr 28, 2026 5:57pm
comark-nuxt Ready Ready Preview Apr 28, 2026 5:57pm
comark-svelte Ready Ready Preview Apr 28, 2026 5:57pm
comark-twoslash Ready Ready Preview Apr 28, 2026 5:57pm
comark-vue Ready Ready Preview Apr 28, 2026 5:57pm

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 28, 2026

Open in StackBlitz

comark

npm i https://pkg.pr.new/comark@170

@comark/ansi

npm i https://pkg.pr.new/@comark/ansi@170

@comark/html

npm i https://pkg.pr.new/@comark/html@170

@comark/nuxt

npm i https://pkg.pr.new/@comark/nuxt@170

@comark/react

npm i https://pkg.pr.new/@comark/react@170

@comark/svelte

npm i https://pkg.pr.new/@comark/svelte@170

@comark/vue

npm i https://pkg.pr.new/@comark/vue@170

commit: fc5aa12

Copy link
Copy Markdown
Contributor

@farnabaz farnabaz left a comment

Choose a reason for hiding this comment

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

Comark used to use code to tokens at first but in order to support transformers we moved to code to hast.
Switching between these two based on transformers existence is smart move 👍

@farnabaz farnabaz merged commit e5b0843 into main Apr 29, 2026
10 checks passed
@farnabaz farnabaz deleted the perf/highlight-plugin branch April 29, 2026 12:41
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