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

[Memory Leak]: Builds incorporating Shiki Twoslash crash with JavaScript heap out of memory errors #4242

Open
4 tasks done
IMax153 opened this issue Sep 30, 2024 · 5 comments
Labels
bug Something isn't working perf upstream Related to the dependencies

Comments

@IMax153
Copy link

IMax153 commented Sep 30, 2024

Describe the bug

Hello 👋 from the Effect-TS community :)

We have recently been experimenting with using different frameworks for building our documentation website. I decided to try building our documentation with Vitepress because of your native integration with Shiki Twoslash (via @shikijs/vitepress-twoslash), which we make extensive use of in our docs.

However, when I attempt to build our documentation with Vitepress and Shiki Twoslash, I consistently receive a JavaScript heap out of memory error. I have attempted to increase the --max-old-space-size to ~8GB and still encounter this issue.

With Twoslash Integration

Example of Vitepress build resulting in OOM error

In my .vitepress/config.ts, if I remove the transformerTwoslash from the markdown.codeTransformers array, the build succeeds without issue in ~20 seconds.

Without Twoslash Integration

Example of Vitepress build succeeding

Also, please let me know if it is more appropriate to move this issue to the Shiki project. If so, I have no problem closing this issue and moving it 👍 Thank you for your time!

Reproduction

  1. Clone our docs experiment

    git clone https://github.com/IMax153/vitepress-memory-leak-repro.git
  2. Install dependencies

    pnpm install
  3. Attempt to build

    pnpm build

Expected behavior

My expected behavior would be for Vitepress to be able to build our docs with Shiki Twoslash integrated without issue.

System Info

System:
    OS: macOS 14.6.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 1.99 GB / 16.00 GB
    Shell: 5.9 - /nix/store/w53pgqwh5dm38skdd7n7wn0k6cw72jzj-zsh-5.9/bin/zsh
Binaries:
    Node: 20.17.0 - /nix/store/hxl1k8qgmrm1vfq5f419iv4wybz9szqq-nodejs-20.17.0/bin/node
    npm: 10.8.2 - /nix/store/hxl1k8qgmrm1vfq5f419iv4wybz9szqq-nodejs-20.17.0/bin/npm
    pnpm: 9.10.0 - /nix/store/ddjsxwcpw09llisgvw7drvr92dbkg4mi-corepack-nodejs-20.17.0/bin/pnpm
Browsers:
    Chrome: 129.0.6668.70
    Safari: 17.6
npmPackages:
    vitepress: ^1.3.4 => 1.3.4

Note: I use Nix for provisioning my system, hence the strange looking binary paths.

Additional context

I've included a script in the package.json that reduces the available NodeJS heap memory (to force an OOM earlier) and takes a heap snapshot right before an OOM error occurs in case that is useful for you folks.

pnpm build:snapshot

Validations

@IMax153 IMax153 added the bug: pending triage Maybe a bug, waiting for confirmation label Sep 30, 2024
@brc-dd
Copy link
Member

brc-dd commented Sep 30, 2024

Yeah https://github.com/shikijs/shiki/issues might be better place to post this. I'm fine with keeping this open if it's indeed a memory leak with vitepress.

@brc-dd brc-dd added bug Something isn't working upstream Related to the dependencies perf and removed bug: pending triage Maybe a bug, waiting for confirmation labels Sep 30, 2024
@IMax153
Copy link
Author

IMax153 commented Sep 30, 2024

https://github.com/shikijs/shiki/issues might be better place to post this

No problem, makes sense to me - I've gone ahead and opened an issue upstream. Linking here for tracking purposes: shikijs/shiki#796

@jasonkuhrt
Copy link

I started experiencing these issues today with Graffle's website as well. https://github.com/jasonkuhrt/graffle/actions/runs/11129348920/job/30926231362?pr=1151. Nothing more to add than what @IMax153 has already said.

@brc-dd
Copy link
Member

brc-dd commented Oct 1, 2024

@jasonkuhrt If possible, do you have the exact commit which started giving these? If it's recent then it might have something to do with newer shiki releases. 👀

@jasonkuhrt
Copy link

jasonkuhrt commented Oct 1, 2024

Hey @brc-dd, it started failing on this commit ade5a3e61ad536484968880d9218bdcdf4a66ac1. It's a huge commit unfortunately. You can see under the website directory no version of any dependencies changed in it fwiw.

jasonkuhrt added a commit to jasonkuhrt/graffle that referenced this issue Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working perf upstream Related to the dependencies
Projects
None yet
Development

No branches or pull requests

3 participants