-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: (gatsby-plugin-manifest) misc code and doc updates (#12757)
## 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
1 parent
881e5a7
commit 01670e1
Showing
13 changed files
with
774 additions
and
639 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.