Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poor performance of "getting started" @shikijs/markdown-it code #853

Open
4 of 5 tasks
hyperupcall opened this issue Nov 28, 2024 · 1 comment
Open
4 of 5 tasks

Comments

@hyperupcall
Copy link

Validations

Describe the bug

Thanks for making this tool! I'm using Shiki through the shikijs/markdown-it package. I used the code as per the instructions (full code in repro):

import Shiki from '@shikijs/markdown-it'
import MarkdownIt from 'markdown-it'

const md = MarkdownIt()

md.use(await Shiki({
  themes: {
    light: 'vitesse-light',
    dark: 'vitesse-dark',
  }
}))

It surprised me that this takes several seconds to execute (~4.6 seconds with dev tools open (image/trace below)).

image
shiki2.cpuprofile

This was a bit surprising to me since I assumed the "getting started code" wouldn't perform that poorly. Fixing the issue was straightforward (I specified the langs: [...] field on initialization), but I brought this up because I don't think I'm the first or last one to run into this surprise. And this "getting started" code may cause people to have the perception that ShikiJS is slower than it actually is. I myself, assumed that this code executed pretty quickly and that languages were loaded lazily (while evaluating Markdown text). Not sure the right approach for addressing this concern, but if it's a simple docs fix, I'd be happy to make a PR

Reproduction

https://github.com/fox-archives/repro-shiki-perf

Contributes

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests
@antfu
Copy link
Member

antfu commented Nov 29, 2024

Sure, PR welcome! The reason we didn't mention that before because for markdown, if you don't control the content, it might need any languages. Also because that markdown-it doesn't support async highlighting, we can't load languages on-demand. I am good with improve the docs by mention the trade-offs here.

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

No branches or pull requests

2 participants