Skip to content

Commit

Permalink
refactor: (gatsby-plugin-manifest) misc code and doc updates (#12757)
Browse files Browse the repository at this point in the history
## Description

Code and Docs updates for `gatsby-plugin-manifest`

- Finished moving to module imports
- Finished migrating off of `bluebird` and onto async/await (order of magnitude speed increase)
- Major doc updates
- Improve logging output for generation
  • Loading branch information
moonmeister authored and wardpeet committed Apr 8, 2019
1 parent 881e5a7 commit 01670e1
Show file tree
Hide file tree
Showing 13 changed files with 774 additions and 639 deletions.
21 changes: 21 additions & 0 deletions benchmarks/plugin-manifest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# gatsby-plugin-manifest performance tests

- Setup: `yarn`
- Run: `yarn test`

Benchmarks the current production version of the plugin unless you use `gatsby-dev`.

## To benchmark the current branch:

```sh
# In the root of the Gatsby repository
$ yarn run watch --scope=gatsby-plugin-manifest .
```

```sh
# In ./benchmarks/plugin-manifest
# You'll need 'gatsby-dev' installed and configured globally.
$ gatsby-dev --packages gatsby-plugin-manifest
```

You may now switch branches using `git checkout` and edit code on the current branch. Changes will be compiled into the local `node_modules` for the benchmark.
77 changes: 77 additions & 0 deletions benchmarks/plugin-manifest/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const { onPostBootstrap } = require(`gatsby-plugin-manifest/gatsby-node`)
const reporter = require(`gatsby-cli/lib/reporter`)
const fs = require(`fs-extra`)

//Config for executing onPostBootstrap
const pluginOptions = {
name: `GatsbyJS`,
short_name: `GatsbyJS`,
start_url: `/`,
background_color: `#ffffff`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `../../www/src/assets/gatsby-icon.png`,
cache_busting_mode: `none`,
}

//Global Variables
let results = { seconds: [], nanoseconds: [] }
let sum = [0, 0]
let rounds = process.env.TOTAL_ROUNDS || 20

//Execute a single test of onPostBootstrap
async function executeBootstrap() {
const timeStart = process.hrtime()
await onPostBootstrap({ reporter }, pluginOptions)
const timeEnd = process.hrtime(timeStart)

// console.info(
// "Execution time (hr): %ds %dms",
// timeEnd[0],
// timeEnd[1] / 1000000
// )

results.seconds.push(timeEnd[0])
results.nanoseconds.push(timeEnd[1])
sum[0] += timeEnd[0]
sum[1] += timeEnd[1]

fs.removeSync(`public/icons`)
fs.removeSync(`public/manifest.webmanifest`)
}

//Loop test to run multiple times and calculate results
async function runTest() {
console.info(`Timing 'onPostBootstrap' running ${rounds} times.`)

for (let i = 0; i < rounds; i++) {
// process.stdout.write(`Round ${i + 1}: `)
await executeBootstrap(i)
}

let averageSum = [0, 0]
averageSum[0] = sum[0] / rounds
averageSum[1] = sum[1] / rounds

console.info(
`\nAverage execution time (hr): %ds %dms`,
averageSum[0],
averageSum[1] / 1000000
)

console.info(
`\nMax execution time (hr): ${Math.max(...results.nanoseconds) / 1000000}ms`
)
console.info(
`\nMin execution time (hr): ${Math.min(...results.nanoseconds) / 1000000}ms`
)

console.info(
`\nRange execution time (hr): ${(Math.max(...results.nanoseconds) -
Math.min(...results.nanoseconds)) /
1000000}ms`
)
}

//execute
runTest()
15 changes: 15 additions & 0 deletions benchmarks/plugin-manifest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "benchmark-gatsby-plugin-manifest",
"version": "1.0.0",
"description": "Run manifest lots of times",
"main": "index.js",
"scripts": {
"test": "node index.js"
},
"author": "Alex Moon <alex.jared.moon@gmail.com",
"license": "MIT",
"dependencies": {
"fs-extra": "^7.0.1",
"gatsby-plugin-manifest": "^2.0.25"
}
}
Empty file.
Loading

0 comments on commit 01670e1

Please sign in to comment.