0.1.6 • Published 7 months ago

astro-parallel-build-check v0.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

astro-parallel-build-check

Run astro check and astro build in parallel.

Motivation

By default astro runs check and build steps separately, one after the other. This isn't a problem if the checks fail, since we probably don't want to proceed with the build anyway. However if the checks are successful this can be much slower than running them in parallel with the build, especially on machines with multiple CPU cores and projects that spend a lot of time on I/O during builds.

Getting Started

Installation

pnpm add astro-parallel-build-check
yarn add astro-parallel-build-check
npm install astro-parallel-build-check

Usage

Add the astro-parallel-build-check command to the scripts field of your package.json:

{
  "scripts": {
    "build": "astro-parallel-build-check"
  }
}

Benchmark

I used hyperfine to run a quick benchmark of this package versus astro check && astro build

I used an app in testing directory of this repo to run the benchmark. It's the astro blog template that I used to make sure the package works correctly. While this isn't a good example of a real-world app it still demonstrates the performance benefits pretty well.

To get consistent results accross benchmark runs, I used --prepare argument to remove the dist folder and flush disk caches. If you are not on MacOS sync && sudo purge will not do the job, so you'll need to look up how to flush the caches on your system.

Since dropping caches likely requires superuser privileges, you can use sudo -v to temporarily gain the permissions before running the benchmark commands.

$ hyperfine --prepare "rm -rf dist && sync && sudo purge" 'pnpm run build'
Benchmark 1: pnpm run build
  Time (mean ± σ):      4.548 s ±  0.061 s    [User: 7.990 s, System: 0.689 s]
  Range (min … max):    4.459 s …  4.619 s    10 runs
$ hyperfine --prepare "rm -rf dist && sync && sudo purge" 'pnpm run build-parallel'
Benchmark 1: pnpm run build-parallel
  Time (mean ± σ):      3.195 s ±  0.063 s    [User: 8.337 s, System: 0.668 s]
  Range (min … max):    3.149 s …  3.342 s    10 runs

We can see that using astro-parallel-build-check results in almost 1.5s faster build.

Limitations

Passing flags to build and check commands is not supported at the moment. I'm holding off on this because I don't need it and there is a chance I'll never do. The best option would probably be to have the same flags as astro build command and pass the astro check configuration as environment variables.

Contact

0.1.6

7 months ago

0.1.5

11 months ago

0.1.4

11 months ago

0.1.2

12 months ago

0.1.3

12 months ago

0.1.1

12 months ago

0.1.0

12 months ago