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

feat(vitepress-twoslash): cache type informations to improve performance #798

Merged
merged 10 commits into from
Nov 15, 2024

Conversation

nakasyou
Copy link
Contributor

@nakasyou nakasyou commented Oct 4, 2024

Description

VitePress Twoslash takes a long time to render large Types.
This PR solves part of this.

This PR can cache type information with the following code:

export default defineConfig({
  markdown: {
    codeTransformers: [
      transformerTwoslash({
        typesCacheDir: './my-custom-cache-dir'
      })
    ]
  }
})

This will cache the type information in the specified directory.
Use a cache such as GitHub Actions with this to speed up your builds

Linked Issues

Nothing

Additional context

ElysiaJS appears to have cut back on Twoslash because it took 30 minutes to build the documentation. This PR may resolve it.
https://x.com/saltyAom/status/1842140132897615963

Copy link

netlify bot commented Oct 4, 2024

Deploy Preview for shiki-matsu ready!

Name Link
🔨 Latest commit d38338d
🔍 Latest deploy log https://app.netlify.com/sites/shiki-matsu/deploys/6736ddc0d6357300081bb249
😎 Deploy Preview https://deploy-preview-798--shiki-matsu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Oct 4, 2024

Deploy Preview for shiki-next ready!

Name Link
🔨 Latest commit d38338d
🔍 Latest deploy log https://app.netlify.com/sites/shiki-next/deploys/6736ddc0d6a7de00084e9b6b
😎 Deploy Preview https://deploy-preview-798--shiki-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@nakasyou nakasyou changed the title feat(vitepress-twoslash): cache type infomations feat(vitepress-twoslash): cache type informations to improve performance Oct 6, 2024
@antfu
Copy link
Member

antfu commented Oct 24, 2024

Sorry it might take a bit longer for me to refactor it a bit to make the logic a bit decoupled - if you want to help with that, could you make typesCacheDir a generic map like typesCache where users could provide their own implementation of how to handle the cache, and then refactor the current logic to a standalone createFilesystemTypesCache(options) factory? Thanks

@nakasyou
Copy link
Contributor Author

Hi @antfu, thank you for commenting.

You mean

const typesCache = createFileSystemTypesCache(options)

transformerTwoslash({
  typesCache
})

, right?

@antfu
Copy link
Member

antfu commented Oct 26, 2024

Yes, something like that

@nakasyou
Copy link
Contributor Author

@antfu could you check this?

@kravetsone
Copy link

kravetsone commented Nov 15, 2024

Great
this really interesting

@antfu antfu merged commit 45fd3ad into shikijs:main Nov 15, 2024
11 checks passed
@nakasyou nakasyou deleted the feat/vitepress-twoslash-cache branch November 15, 2024 06:07
@jasonkuhrt
Copy link

jasonkuhrt commented Nov 15, 2024

This is exciting! I made an issue for Graffle to look more into this when I have time.

When it comes to Vitepress, in my mind it feels like this caching stuff should be the default, and presumably almost no one will need to opt out of it, but if they need to then sure it should be possible. My experience is that local development, not just CI builds, is very slow.

So, in other words I'm hoping that a future vitepress release will just make everything faster without any effort from user needed by default. Curious to see how it will actually land.

Thanks all!

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.

4 participants