Skip to content

bun i with cache is much slower than with no cache #19936

Open

Description

@ermengchao

What version of Bun is running?

1.2.14+6a363a38d

What platform is your computer?

Darwin 24.5.0 arm64 arm

What steps can reproduce the bug?

mkdir test && cd test
bun add -D --no-cache husky
bun rm husky
bun add -D husky
bun rm husky
bun add -D husky

What is the expected behavior?

bun i ... will be faster than bun i ... --no-cache

What do you see instead?

Here's the speed with no cache:

chao@MacBook-Air test % bun i @commitlint/cli @commitlint/config-conventional -D --no-cache
bun add v1.2.14 (6a363a38)

installed @commitlint/[email protected] with binaries:
 - commitlint
installed @commitlint/[email protected]

101 packages installed [7.82s]

remove:

chao@MacBook-Air test % bun rm @commitlint/cli @commitlint/config-conventional
bun remove v1.2.14 (6a363a38)

- @commitlint/cli
- @commitlint/config-conventional
2 packages removed [2.00ms]

package.json has no dependencies! Deleted empty lockfile

since bun i --no-cache will not create cache, I run the following command to add cache:

chao@MacBook-Air test % bun i @commitlint/cli @commitlint/config-conventional -D           
bun add v1.2.14 (6a363a38)

installed @commitlint/[email protected] with binaries:
 - commitlint
installed @commitlint/[email protected]

2 packages installed [242.50s]

remove again:

chao@MacBook-Air test % bun rm @commitlint/cli @commitlint/config-conventional
bun remove v1.2.14 (6a363a38)

- @commitlint/cli
- @commitlint/config-conventional
2 packages removed [2.00ms]

package.json has no dependencies! Deleted empty lockfile

install with cache:

chao@MacBook-Air test % bun i @commitlint/cli @commitlint/config-conventional -D
bun add v1.2.14 (6a363a38)

installed @commitlint/[email protected] with binaries:
 - commitlint
installed @commitlint/[email protected]

2 packages installed [491.09s]

You can see that bun i with cache took much time than that with no cache.
Here's the table:

run command wall-clock cache state
1 bun i … --no-cache 7.82 s cache bypassed & not written
2 bun i … 242.50 s cache populated for the first time
3 bun i … 491.09 s cache already full

Additional information

My configurations:

export BUN_INSTALL_BIN="/Users/chao/.local/bin"
export BUN_INSTALL_GLOBAL_DIR="$XDG_DATA_HOME/bun"
export BUN_INSTALL_CACHE_DIR="$XDG_CACHE_HOME/bun"

Activity

  1. added
    bun installSomething that relates to the npm-compatible client
    performanceAn issue with performance
    and removed on May 27, 2025
  2. RiskyMH commented on May 28, 2025

    @RiskyMH
    Contributor

    Interesting, sadly it does seem to work better for me though (maybe it has better resources being M3 max)

    risky@BunBook-Pro 19936 % mkdir test && cd test
    bun add -D --no-cache husky
    bun rm husky
    bun add -D husky
    bun rm husky
    bun add -D husky
    bun add v1.2.15-canary.37 (392212b0)
    
    installed [email protected] with binaries:
     - husky
    
    1 package installed [233.00ms]
    bun remove v1.2.15-canary.37 (392212b0)
    
    - husky
    1 package removed [1.00ms]
    
    package.json has no dependencies! Deleted empty lockfile
    bun add v1.2.15-canary.37 (392212b0)
    
    installed [email protected] with binaries:
     - husky
    
    1 package installed [154.00ms]
    bun remove v1.2.15-canary.37 (392212b0)
    
    - husky
    1 package removed [1.00ms]
    
    package.json has no dependencies! Deleted empty lockfile
    bun add v1.2.15-canary.37 (392212b0)
    
    installed [email protected] with binaries:
     - husky
    
    1 package installed [2.00ms]
    
    risky@BunBook-Pro test % bun i @commitlint/cli @commitlint/config-conventional -D --no-cache
    bun add v1.2.15-canary.37 (392212b0)
    
    installed @commitlint/[email protected] with binaries:
     - commitlint
    installed @commitlint/[email protected]
    
    101 packages installed [3.86s]
    
    risky@BunBook-Pro test % bun rm @commitlint/cli @commitlint/config-conventional
    
    bun remove v1.2.15-canary.37 (392212b0)
    
    - @commitlint/cli
    - @commitlint/config-conventional
    2 packages removed [3.00ms]
    
    risky@BunBook-Pro test % bun i @commitlint/cli @commitlint/config-conventional -D           
    
    bun add v1.2.15-canary.37 (392212b0)
    
    installed @commitlint/[email protected] with binaries:
     - commitlint
    installed @commitlint/[email protected]
    
    2 packages installed [3.97s]
    
    risky@BunBook-Pro test % bun rm @commitlint/cli @commitlint/config-conventional
    bun remove v1.2.15-canary.37 (392212b0)
    
    - @commitlint/cli
    - @commitlint/config-conventional
    2 packages removed [3.00ms]
    
    risky@BunBook-Pro test % bun i @commitlint/cli @commitlint/config-conventional -D
    
    bun add v1.2.15-canary.37 (392212b0)
    
    installed @commitlint/[email protected] with binaries:
     - commitlint
    installed @commitlint/[email protected]
    
    2 packages installed [31.00ms]
    
  3. ermengchao commented on May 28, 2025

    @ermengchao
    Author

    Interesting, sadly it does seem to work better for me though (maybe it has better resources being M3 max)

    risky@BunBook-Pro 19936 % mkdir test && cd test
    bun add -D --no-cache husky
    bun rm husky
    bun add -D husky
    bun rm husky
    bun add -D husky
    bun add v1.2.15-canary.37 (392212b0)
    
    installed [email protected] with binaries:
     - husky
    
    1 package installed [233.00ms]
    bun remove v1.2.15-canary.37 (392212b0)
    
    - husky
    1 package removed [1.00ms]
    
    package.json has no dependencies! Deleted empty lockfile
    bun add v1.2.15-canary.37 (392212b0)
    
    installed [email protected] with binaries:
     - husky
    
    1 package installed [154.00ms]
    bun remove v1.2.15-canary.37 (392212b0)
    
    - husky
    1 package removed [1.00ms]
    
    package.json has no dependencies! Deleted empty lockfile
    bun add v1.2.15-canary.37 (392212b0)
    
    installed [email protected] with binaries:
     - husky
    
    1 package installed [2.00ms]
    
    risky@BunBook-Pro test % bun i @commitlint/cli @commitlint/config-conventional -D --no-cache
    bun add v1.2.15-canary.37 (392212b0)
    
    installed @commitlint/[email protected] with binaries:
    - commitlint
    installed @commitlint/[email protected]
    
    101 packages installed [3.86s]
    
    risky@BunBook-Pro test % bun rm @commitlint/cli @commitlint/config-conventional
    
    bun remove v1.2.15-canary.37 (392212b0)
    
    - @commitlint/cli
    - @commitlint/config-conventional
    2 packages removed [3.00ms]
    
    risky@BunBook-Pro test % bun i @commitlint/cli @commitlint/config-conventional -D           
    
    bun add v1.2.15-canary.37 (392212b0)
    
    installed @commitlint/[email protected] with binaries:
    - commitlint
    installed @commitlint/[email protected]
    
    2 packages installed [3.97s]
    
    risky@BunBook-Pro test % bun rm @commitlint/cli @commitlint/config-conventional
    bun remove v1.2.15-canary.37 (392212b0)
    
    - @commitlint/cli
    - @commitlint/config-conventional
    2 packages removed [3.00ms]
    
    risky@BunBook-Pro test % bun i @commitlint/cli @commitlint/config-conventional -D
    
    bun add v1.2.15-canary.37 (392212b0)
    
    installed @commitlint/[email protected] with binaries:
    - commitlint
    installed @commitlint/[email protected]
    
    2 packages installed [31.00ms]
    

    Thanks for your reproduction and response! I use stats as the system monitor on my mac, and when I ran the bun i commands, I didn't notice any significant CPU or memory load. So unfortunately I don’t think it has anything to do with system resources.

    However, when I tried reproducing the issue twice today, it didn’t occur the first time, but it did reappear the second time(I'm sure that I've run the same commands). So maybe it was just an unusual bug, and just wait a moment happened to fix it? 😂 I really have no idea.

    For the second time here's the verbose output:

    chao@MacBook-Air tt % bun add -D husky --verbose
    bun add v1.2.14 (6a363a38)
    Enqueue package manifest for download: husky
      🔍 Resolving [1/1] [fetch] > HTTP/1.1 GET https://registry.npmjs.org/husky
    [fetch] > If-None-Match: W/"ff123ffcf88d8a53581952da517da026"
    [fetch] > Accept: application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*
    [fetch] > Connection: keep-alive
    [fetch] > User-Agent: Bun/1.2.14
    [fetch] > Host: registry.npmjs.org
    [fetch] > Accept-Encoding: gzip, deflate, br, zstd
    
    [fetch] < 200 Connection established
    
    [fetch] < 304 Not Modified
    [fetch] < Date: Wed, 28 May 2025 18:20:04 GMT
    [fetch] < Connection: keep-alive
    [fetch] < CF-Ray: 946fc3906ff4dfed-NRT
    [fetch] < CF-Cache-Status: HIT
    [fetch] < Access-Control-Allow-Origin: *
    [fetch] < Age: 18
    [fetch] < Cache-Control: public, max-age=300
    [fetch] < ETag: "ff123ffcf88d8a53581952da517da026"
    [fetch] < Last-Modified: Sat, 11 Jan 2025 17:19:04 GMT
    [fetch] < Vary: Accept-Encoding
    [fetch] < Set-Cookie: _cfuvid=OrIESiNAQ6_KxOfM.VosdUACC3KrJFLddHAoF4rglPM-1748456404570-0.0.1.1-604800000; path=/; domain=.npmjs.org; HttpOnly; Secure; SameSite=None
    [fetch] < Server: cloudflare
    
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
    [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
    [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
      🔍 Resolving [1/1] [PackageManager] waiting for 1 tasks
        [60.27s]
    Downloaded husky versions
       - "husky": "" - [email protected]
    Clean lockfile: 2 packages - 2 packages in 612us
    
    -- BEGIN SHA512/256(`${alphabetize(name)}@${order(version)}`) --
    [email protected]
    -- END HASH--
    
    + [email protected]
    
    1 package installed [60.28s]

    It keeps waiting for the tasks, and that's the case why bun install takes so long. I've asked ChatGPT for help, he inferred that maybe the cache was too large, which might take a long time to be scanned. But when I either delete the cache manually or run bun pm cache rm, it doesn't work.

    Again, thanks for your patience! I'm a college student from China, a newbie to both coding and the GitHub community. Your efforts to maintain such a great open-source project and support the community is really cool!!! I hope I can be the one with open-source spirit and contribute to open source like you in the future! 😎

  4. bmakan commented on Jun 17, 2025

    @bmakan

    I can confirm using --no-cache resolved my "endless" resolving issue as well.

    I do use company proxy. Maybe that's the root of it.

  5. jacquesbh commented on Aug 10, 2025

    @jacquesbh

    I confirm the same behavior, running on macos M3 Max.

  6. rekram1-node commented on Jan 1, 2026

    @rekram1-node
    Contributor

    Yeah when behind a proxy, --no-cache is basically a requirement for me, otherwise it seems to hang forever

  7. jacquesbh commented on Jan 2, 2026

    @jacquesbh

    After updating Opencode, I run this command:

    cp ~/.config/opencode/bunfig.toml ~/.cache/opencode/
    

    The bunfig.toml:

    [install.cache]
    disable = true

    Basically to disable caching on bun.

    That's the only solution I found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbun installSomething that relates to the npm-compatible clientperformanceAn issue with performance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions