question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance opportunity for yarn 3 cache

See original GitHub issue

Thanks for the new cache feature. Much easier.

After few weeks, I realized that while it supports yarn, there’s some improvements that can be made.

Yarn 3 (probably yarn 2+ too) manages downloaded archives pretty well (.yarn/cache/*.zip) and invalidating on yarn.lock changes does not take that into account and I saw a lot of cache misses.

As an example I converted back to action-cache to illustrate and test.

I’m wondering if a similar approach could be done with setup-node ?

Updated example with action cache

Updated on Nov 23th, taking into account @merceyz comment.

Setup action

      # Get the yarn cache path.
      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
    
      - name: Restore yarn cache
        uses: actions/cache@v2
        id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: yarn-cache-folder-${{ hashFiles('**/yarn.lock', '.yarnrc.yml') }}
          restore-keys: |
            yarn-cache-folder-

Testing a cache hit after adding a dependency

With setup node cache, as the yarn.lock have changed all packages would be fetched again (1m 28s) rather than (1s 124ms). Environmentally friendlier 🌳

yarn install --immutable
➤ YN0000: ┌ Fetch step
  ➤ YN0013: │ 1719 packages were already cached, one had to be fetched (superjson@npm:1.7.5)
➤ YN0000: └ Completed in 1s 124ms

Cache Size: ~127 MB (133261279 B)
Cache saved successfully
Cache saved with key: yarn-cache-folder-os-Linux-node--f118ea4bee07eada9df36ad2e83fd6febcbaf06b5b8962689c7650659e872ad3

PS: Key points

~Example with action cache~ (old version, before @merceyz improvements)
      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
      - name: Restore yarn cache
        uses: actions/cache@v2
        id: yarn-cache 
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}       
          key: yarn-cache-folder-os-${{ runner.os }}-node-${{ env.node-version }}-${{ hashFiles('**/yarn.lock', '.yarnrc.yml') }}      
          restore-keys: |
            yarn-cache-folder-os-${{ runner.os }}-node-${{ env.node-version }}-
            yarn-cache-folder-os-${{ runner.os }}-

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:19
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
belgattitudecommented, Oct 10, 2022

Just to share, here’s my updated composite action for

  1. yarn 3+ with node-modules linker: https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a
  2. pnpm 7+: https://gist.github.com/belgattitude/838b2eba30c324f1f0033a797bab2e31
2reactions
merceyzcommented, Sep 10, 2021

It can be even more efficient by not including the OS and Node version in the cache key as well - https://github.com/actions/setup-node/pull/272#issuecomment-873564091

Read more comments on GitHub >

github_iconTop Results From Across the Web

yarn cache
Yarn stores every package in a global cache in your user directory on the file system. yarn cache list will print out every...
Read more >
Prevent user cache from using large amounts of disk space in ...
On an Amazon EMR cluster, YARN is configured to allow jobs to write cache data to /mnt/yarn/usercache. When you process a large amount...
Read more >
How to fix security vulnerabilities in Yarn - Debricked
Yarn is a popular Node.JS package manager, notable for improved performance and security compared to the default npm package manager.
Read more >
Apache Hadoop 3.3.4 – Hadoop: Capacity Scheduler
Here is an example with three top-level child-queues a, ... <property> <name>yarn.scheduler.capacity.root.queues</name> <value>a,b,c</value> ...
Read more >
YARN Properties in Cloudera Runtime 7.1 | CDP Private Cloud
This can improve performance of many jobs that are shuffle-intensive. Experimental in CDH 5.2. Related Name: Default Value: false; API Name ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found