forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix/path-bug
* master: (45 commits) chore(release): Publish next pre-minor fix(gatsby-source-shopify): fix linting (gatsbyjs#31291) fix(deps): update minor and patch for gatsby-plugin-preact (gatsbyjs#31169) chore: add gatsby-plugin-gatsby-cloud to renovate chore: update renovatebot config to support more packages (gatsbyjs#31289) chore(deps): update dependency @types/semver to ^7.3.5 (gatsbyjs#31148) fix(deps): update minor and patch for gatsby-plugin-manifest (gatsbyjs#31160) fix(deps): update minor and patch for gatsby-remark-copy-linked-files (gatsbyjs#31163) fix(deps): update dependency mini-css-extract-plugin to v1.6.0 (gatsbyjs#31158) chore(deps): update dependency @testing-library/react to ^11.2.6 (gatsbyjs#31168) docs(gatsby-source-shopify): Updates Shopify README with new plugin info (gatsbyjs#31287) chore: run yarn deduplicate (gatsbyjs#31285) docs(gatsby-plugin-image): Add docs for customizing default options (gatsbyjs#30344) fix(gatsby-plugin-image): print error details (gatsbyjs#30417) chore(docs): Update "Adding Search with Algolia" guide (gatsbyjs#29460) chore(docs): Update MDX frontmatter for programmatic pages (gatsbyjs#29798) docs: Add image plugin architecture doc (gatsbyjs#31096) perf(gatsby): use fastq instead of better-queue + refactor (gatsbyjs#31269) feat(gatsby-plugin-image): Export ImageDataLike type (gatsbyjs#30590) fix(gatsby): update plugin api types (gatsbyjs#30819) ...
- Loading branch information
Showing
326 changed files
with
17,244 additions
and
17,075 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
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
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,43 @@ | ||
# Filters and sort benchmark | ||
|
||
Stress tests various query filters (with and without sorting by random value). | ||
|
||
# Usage | ||
|
||
```shell | ||
NUM_NODES=1000 NUM_PAGES=1000 FILTER=eq SORT=1 TEXT=1 yarn bench | ||
``` | ||
|
||
Explanation: | ||
|
||
- `FILTER`: one of `eq`, `gt`, `gt-lt`, `in`, `lt`, `ne`, `nin`, `regex`, `elemMatch-eq` (default: `eq`). | ||
See `src/templates` for specific queries. | ||
- `SORT`: when set, the benchmark will also add sorting to the query (by random integer value) | ||
- `TEXT`: all nodes are lightweight by default (just 5 fields with numeric values or short strings).\ | ||
When settings this env variable - each node will get additional field with 4k of text | ||
(useful for memory usage measurements) | ||
- `NUM_NODES`: the number of nodes created (1000 by default) | ||
- `NUM_PAGES`: the number of pages created (1000 by default, must be >= `NUM_NODES`) | ||
|
||
# Example | ||
|
||
Let's figure out time complexity of `gt` filter. To make this happen - let's run the benchmark | ||
3 times with the same number of pages but growing number of nodes: | ||
|
||
### run 1: | ||
|
||
```shell | ||
NUM_NODES=1000 FILTER=gt yarn bench | ||
``` | ||
|
||
### run 2: | ||
|
||
```shell | ||
NUM_NODES=10000 FILTER=gt yarn bench | ||
``` | ||
|
||
### run 3: | ||
|
||
```shell | ||
NUM_NODES=100000 FILTER=gt yarn bench | ||
``` |
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,8 @@ | ||
module.exports = { | ||
siteMetadata: { | ||
title: `Gatsby Benchmark Filters & Sort`, | ||
description: `The filters and sort benchmark`, | ||
author: `@gatsbyjs`, | ||
}, | ||
// plugins: [`gatsby-plugin-benchmark-reporting`], | ||
} |
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,87 @@ | ||
const NUM_PAGES = parseInt(process.env.NUM_PAGES || 1000, 10) | ||
const NUM_NODES = parseInt(process.env.NUM_NODES || NUM_PAGES, 10) | ||
const SORT = process.env.SORT | ||
const FILTER = process.env.FILTER || `eq` | ||
const TEXT = Boolean(process.env.TEXT) | ||
|
||
if (NUM_NODES < NUM_PAGES) { | ||
throw new Error("Expecting NUM_NODES >= NUM_PAGES") | ||
} | ||
|
||
const nodesPerPage = Math.max(1, Math.round(NUM_NODES / NUM_PAGES)) | ||
const ptop = require(`process-top`)() | ||
|
||
exports.sourceNodes = async ({ actions: { createNode } }) => { | ||
console.log(`Creating ${NUM_NODES} nodes`) | ||
for (let nodeNum = 0; nodeNum < NUM_NODES; nodeNum++) { | ||
const pageNum = Math.floor(nodeNum / nodesPerPage) | ||
createNode({ | ||
id: String(nodeNum), | ||
nodeNum, | ||
pageNum, | ||
nodeNumReversed: NUM_NODES - nodeNum, | ||
testEq: String(nodeNum), | ||
testIn: [`foo`, `bar`, `baz`, `foobar`][nodeNum % 4], | ||
testElemMatch: [ | ||
{ testIn: [`foo`, `bar`, `baz`, `foobar`][nodeNum % 4] }, | ||
{ testEq: String(nodeNum) }, | ||
], | ||
text: `${TEXT ? new Array(4128).join("*") : ``}${nodeNum}`, | ||
sortRandom: Math.random() * NUM_NODES, | ||
internal: { | ||
type: `Test`, | ||
contentDigest: String(nodeNum), | ||
}, | ||
}) | ||
if (nodeNum % 50 === 0) { | ||
await new Promise(resolve => setTimeout(resolve, 3)) | ||
} | ||
} | ||
if (global.gc) { | ||
global.gc() | ||
} | ||
console.log(ptop.toString()) | ||
} | ||
|
||
const pageTemplate = require.resolve(`./src/templates/${FILTER}.js`) | ||
exports.createPages = async ({ actions: { createPage } }) => { | ||
console.log(`Creating ${NUM_PAGES} pages for filter: ${FILTER}`) | ||
for (let pageNum = 0; pageNum < NUM_PAGES; pageNum++) { | ||
createPage({ | ||
path: `/path/${pageNum}/`, | ||
component: pageTemplate, | ||
context: { | ||
pageNumAsStr: String(pageNum), | ||
fooBarValues: [ | ||
[`foo`, `bar`, `baz`, `foobar`][pageNum % 4], | ||
[`foo`, `bar`, `baz`, `foobar`][(pageNum + 1) % 4], | ||
], | ||
intValue: pageNum, | ||
pageNum: pageNum, | ||
pagesLeft: NUM_PAGES - pageNum, | ||
limit: nodesPerPage, | ||
skip: nodesPerPage * pageNum, | ||
nodesTotal: NUM_NODES, | ||
pagesTotal: NUM_PAGES, | ||
sort: SORT | ||
? { fields: ["sortRandom"], order: SORT === `1` ? `ASC` : `DESC` } | ||
: undefined, | ||
regex: `/^${String(pageNum).slice(0, 1)}/`, // node id starts with the same number as page id | ||
}, | ||
}) | ||
if (pageNum % 50 === 0) { | ||
await new Promise(resolve => setTimeout(resolve, 3)) | ||
} | ||
} | ||
if (global.gc) { | ||
global.gc() | ||
} | ||
console.log(ptop.toString()) | ||
} | ||
|
||
exports.onPostBuild = () => { | ||
if (global.gc) { | ||
global.gc() | ||
} | ||
console.log(ptop.toString()) | ||
} |
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 @@ | ||
{ | ||
"name": "gatsby-starter-hello-world", | ||
"description": "Gatsby hello world starter", | ||
"license": "MIT", | ||
"scripts": { | ||
"bench": "gatsby clean && rimraf .data && node --max_old_space_size=16384 --expose-gc node_modules/gatsby/dist/bin/gatsby.js build", | ||
"develop": "gatsby develop", | ||
"build": "gatsby build", | ||
"serve": "gatsby serve" | ||
}, | ||
"dependencies": { | ||
"gatsby": "^3.4.1", | ||
"process-top": "^1.2.0", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"rimraf": "^3.0.2" | ||
}, | ||
"devDependencies": { | ||
"gatsby-plugin-benchmark-reporting": "*" | ||
} | ||
} |
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,3 @@ | ||
import React from "react" | ||
|
||
export default () => <div>Hello world!</div> |
26 changes: 26 additions & 0 deletions
26
benchmarks/query-filters-sort/src/templates/elemMatch-eq.js
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,26 @@ | ||
import React from "react" | ||
import { graphql } from "gatsby" | ||
|
||
export default ({ data }) => { | ||
if (!data?.allTest?.nodes) { | ||
throw new Error("Wrong data") | ||
} | ||
return <div>{JSON.stringify(data)}</div> | ||
} | ||
|
||
export const query = graphql` | ||
query($pageNumAsStr: String, $sort: TestSortInput) { | ||
allTest( | ||
filter: { | ||
testElemMatch: { elemMatch: { testEq: { eq: $pageNumAsStr } } } | ||
} | ||
sort: $sort | ||
limit: 5 | ||
) { | ||
nodes { | ||
nodeNum | ||
text | ||
} | ||
} | ||
} | ||
` |
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,20 @@ | ||
import React from "react" | ||
import { graphql } from "gatsby" | ||
|
||
export default ({ data }) => { | ||
if (!data?.allTest?.nodes) { | ||
throw new Error("Bad query result") | ||
} | ||
return <div>{JSON.stringify(data)}</div> | ||
} | ||
|
||
export const query = graphql` | ||
query($pageNumAsStr: String!, $sort: TestSortInput) { | ||
allTest(filter: { testEq: { eq: $pageNumAsStr } }, sort: $sort, limit: 5) { | ||
nodes { | ||
nodeNum | ||
text | ||
} | ||
} | ||
} | ||
` |
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,24 @@ | ||
import React from "react" | ||
import { graphql } from "gatsby" | ||
|
||
export default ({ data }) => { | ||
if (!data?.allTest?.nodes) { | ||
throw new Error("Wrong data") | ||
} | ||
return <div>{JSON.stringify(data)}</div> | ||
} | ||
|
||
export const query = graphql` | ||
query($pageNum: Int, $pagesTotal: Int, $sort: TestSortInput) { | ||
allTest( | ||
filter: { nodeNum: { gt: $pageNum, lt: $pagesTotal } } | ||
sort: $sort | ||
limit: 5 | ||
) { | ||
nodes { | ||
nodeNum | ||
text | ||
} | ||
} | ||
} | ||
` |
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,20 @@ | ||
import React from "react" | ||
import { graphql } from "gatsby" | ||
|
||
export default ({ data }) => { | ||
if (!data?.allTest?.nodes) { | ||
throw new Error("Wrong data") | ||
} | ||
return <div>{JSON.stringify(data)}</div> | ||
} | ||
|
||
export const query = graphql` | ||
query($pagesLeft: Int, $sort: TestSortInput) { | ||
allTest(filter: { nodeNum: { gt: $pagesLeft } }, sort: $sort, limit: 5) { | ||
nodes { | ||
nodeNum | ||
text | ||
} | ||
} | ||
} | ||
` |
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,20 @@ | ||
import React from "react" | ||
import { graphql } from "gatsby" | ||
|
||
export default ({ data }) => { | ||
if (!data?.allTest?.nodes?.length) { | ||
throw new Error("Wrong data") | ||
} | ||
return <div>{JSON.stringify(data)}</div> | ||
} | ||
|
||
export const query = graphql` | ||
query($fooBarValues: [String!], $sort: TestSortInput) { | ||
allTest(filter: { testIn: { in: $fooBarValues } }, sort: $sort, limit: 5) { | ||
nodes { | ||
nodeNum | ||
text | ||
} | ||
} | ||
} | ||
` |
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,24 @@ | ||
import React from "react" | ||
import { graphql } from "gatsby" | ||
|
||
export default ({ data }) => { | ||
if (!data?.allTest?.nodes) { | ||
throw new Error("Wrong data") | ||
} | ||
return <div>{JSON.stringify(data)}</div> | ||
} | ||
|
||
export const query = graphql` | ||
query($pageNum: Int, $sort: TestSortInput) { | ||
allTest( | ||
filter: { nodeNumReversed: { lt: $pageNum } } | ||
sort: $sort | ||
limit: 5 | ||
) { | ||
nodes { | ||
nodeNum | ||
text | ||
} | ||
} | ||
} | ||
` |
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,20 @@ | ||
import React from "react" | ||
import { graphql } from "gatsby" | ||
|
||
export default ({ data }) => { | ||
if (!data?.allTest?.nodes) { | ||
throw new Error("Invalid data") | ||
} | ||
return <div>{JSON.stringify(data)}</div> | ||
} | ||
|
||
export const query = graphql` | ||
query($pageNumAsStr: String!, $sort: TestSortInput) { | ||
allTest(filter: { testEq: { ne: $pageNumAsStr } }, sort: $sort, limit: 5) { | ||
nodes { | ||
nodeNum | ||
text | ||
} | ||
} | ||
} | ||
` |
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,20 @@ | ||
import React from "react" | ||
import { graphql } from "gatsby" | ||
|
||
export default ({ data }) => { | ||
if (!data?.allTest?.nodes) { | ||
throw new Error("Invalid data") | ||
} | ||
return <div>{JSON.stringify(data)}</div> | ||
} | ||
|
||
export const query = graphql` | ||
query($fooBarValues: [String!], $sort: TestSortInput) { | ||
allTest(filter: { testIn: { nin: $fooBarValues } }, sort: $sort, limit: 5) { | ||
nodes { | ||
nodeNum | ||
text | ||
} | ||
} | ||
} | ||
` |
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,20 @@ | ||
import React from "react" | ||
import { graphql } from "gatsby" | ||
|
||
export default ({ data }) => { | ||
if (!data?.allTest?.nodes?.length) { | ||
throw new Error("Wrong data") | ||
} | ||
return <div>{JSON.stringify(data)}</div> | ||
} | ||
|
||
export const query = graphql` | ||
query($regex: String, $sort: TestSortInput) { | ||
allTest(filter: { id: { regex: $regex } }, sort: $sort, limit: 5) { | ||
nodes { | ||
nodeNum | ||
text | ||
} | ||
} | ||
} | ||
` |
Oops, something went wrong.