JIHYEONJEONG
Robust Project Structure

Windows에서 pnpm이 느린 이유에 대한 서치

Windows powershell 환경에서 pnpm이 왜 느린지에 대해 알아본다.

Problem - 시나리오를 생각해 보자.

이번 프로젝트는 나 제외 모든 팀원이 Windows에서 개발을 했다. 패키지 매니저로는 pnpm을 사용했는데 Windows에서 pnpm i 및 node_modules 삭제가 심각하게 느려지는 현상을 겪었다. 여기에 대해서 확인해 본다.

  • stackoverflow 에 따르면 디펜던시를 다운 받고 설치할 때마다 Windows Defender의 안티바이러스 검사와 함께 쓰기 허가를 요청하기 때문에 npm처럼 수많은 작은 용량의 파일을 내려받을 경우 바이러스 검사 시간이 늘어나 시간이 늘어난다고 설명하고 있다.

테스트를 위해서 윈도우에서 직접 이 프로젝트를 다운받아 pnpm i 를 해보았을 때 총 14분이 걸렸다. 그냥 npm i으로는 총 108초가 걸렸다.

Goal - Windows에서 개발할 때 어떤 패키지 매니저가 가장 나은지?

원인은 무엇일까?

"dependencies": {

    "@hookform/resolvers": "^3.3.0",

    "@tanstack/react-query": "^5.36.0",

    "@types/node": "20.5.6",

    "@types/react": "18.2.21",

    "@types/react-dom": "18.2.7",

    "@types/three": "^0.167.1",

    "autoprefixer": "10.4.15",

    "eslint": "^8.56.0",

    "eslint-config-next": "13.4.19",

    "framer-motion": "^10.16.4",

    "next": "^15.5.4",

    "postcss": "8.4.28",

    "react": "^19.1.1",

    "react-dom": "^19.1.1",

    "react-hook-form": "^7.45.4",

    "react-loading-skeleton": "^3.4.0",

    "react-rnd": "^10.4.1",

    "sass": "^1.85.1",

    "styled-component": "^2.8.0",

    "styled-components": "^6.0.7",

    "tailwindcss": "3.3.3",

    "three": "^0.167.1",

    "typescript": "5.2.2",

    "uuid": "^9.0.1",

    "vanta": "^0.5.24",

    "yup": "^1.2.0",

    "zod": "^3.22.2"

  },

실제 package.json에는 흥미본위로 깔아본 몇 가지의 라이브러리 말고는 크게 없는 상황이었고 여기서 가장 용량이 많다 할 수 있는 라이브러리는 각각 30mb의 nextjs와 three였다.

어떤 환경에서 느려질까?

Macbook에서 똑같은 액션을 수행헀을 때는 11초가 걸렸다.

actioncachelockfilenode_modulesnpmpnpmYarnYarn PnP
install35.6s8.7s7.6s3.6s
install1.3s764ms5.2sn/a
install9.2s2.3s5.4s1.3s
install13.9s6.1s7.4s3s
install12.6s5.2s5.4s1.3s
install1.6s2.1s7.3sn/a
install1.3s743ms5.2sn/a
install1.6s5.2s7.1sn/a
updaten/an/an/a7.2s3.7s5.9s3.1s
  • pnpm benchmark pnpm 공식 사이트의 벤치마크 정보에는 실제 pnpm과 다른 패키지 매니저간의 차이가 크게 없는 것으로 보이는데...

official issue ticket 1 - 여기 discussion에서는 리눅스 및 mac m2에서도 같은 현상이 있다고 한다.

그리고 위 링크에서 maintainer의 공식 답변을 확인할 수 있었다.

You can try reducing the number of the network-concurrency setting to see if it helps.

I don't think I ever used HDD with pnpm. Antiviruses are known for locking files during installation, which significantly slow pnpm down.

I would still expect pnpm to be faster than Yarn and npm in these cases. Unless you use Yarn with Plug'n'play. Yarn PnP might be faster as it writes the packages into zip files, so there are less file system operations.

Also, this issue doesn't seem useful. pnpm is too slow is too broad... pnpm is not slow as we regularly benchmark it and the competitors do as well. It could be slow in some scenarios or situations. If you have a concrete reproducible scenario, we can look into it. But with this title and description the issue just attracts people with different unrelated issues.

  • pnpm의 setting에서 network-concurrency를 변경하는 것이 도움이 될수 있다.
  • 하드 디스크에서 pnpm을 돌려본 적이 없다. 하지만 윈도우에서는 안티바이러스 때문에 파일 설치가 느린 경우가 이미 잘 알려져 있다.
  • 그럼에도, yarn이나 npm보다는 빠를 것이다. Yarn PnP보다 빠른지는 잘 모르겠다.
  • 하지만 여기 제기한 이슈만으로는 확실히 판단할 수 없다...

여기에 있어서 아직 확실한 답변은 없다. 하지만 이외 다른 사례도 있고 나 역시도 실제 pnpm과 npm 사이의 큰 딜레이를 확인했기 때문에 윈도우에서는 가급적 pnpm을 사용하지 않는 것이 나을 것 같다.

Summary

Windows에서 왜 개발이 느린지?에 대해 알아볼 수 있었다.

Notables

  • powershell에서 rm -rf 커맨드
Get-ChildItem -Path C:\Temp -Include *.* -File -Recurse | foreach { $_.Delete()}
  • rimraf 혹은 해당 라이브러리를 전역에 깔아서 사용한다.

Refs

On this page