Code Monkey home page Code Monkey logo

graphql-parse-benchmark's Introduction

Overview

We are interested to see how long it takes to:

  1. Load and parse JS chunks, containing GraphQL executable documents in different formats
  2. See how long it takes to fully-load each individual chunk (some formats may be lazy-loaded)

Tested formats

Inline GraphQL AST object

export const result1 = { kind: "Document", definitions: [/* generated AST definitions here */] };

GraphQL AST as JSON

export const result1 = JSON.parse('{ kind: "Document", definitions: [...] }');

Lazily parsed GraphQL AST

const graphqlQuery1 = "...";
export const result1 = {
  kind: "Document",
  get definitions() {
    return (
      this.__defs ??
      (this.__defs = parse(graphqlQuery1, { noLocation: true }).definitions)
    );
  },
};
// ... etc;

Eagerly parsed GraphQL AST

const graphqlQuery1 = "...";
export const result1 = parse(graphqlQuery1, { noLocation: true });

Benchmark design

Benchmark contains two steps: CLI for code-generation and runtime.

Code Generator

Generator CLI script relies on 3 hardcoded variables:

  1. List of query template functions
  2. Total number of each query per chunk
  3. Total number of chunks per GraphQL format

Query template function looks like this (expected to return GraphQL query string):

const queryTemplate1 = (i) => `query { foo${i} }`;

As output, script produces JS chunk files on disk:

.
[generated]/
  [inline-graphql-ast]/
    chunk1.js
    chunk2.js
    ...
  [graphql-ast-as-json]/
    chunk1.js
    chunk2.js
    ...
  [lazy-graphql-ast]/
    chunk1.js
    chunk2.js
    ...
  [eager-graphql-ast]/
    chunk1.js
    chunk2.js
    ...

Each chunk exports multiple variables - one variable per generated graphql query. So if there were 3 query templates and total number of each query per chunk is 4, chunk will contain 12 exports (with unique generated queries).

Runtime

Benchmark runs tests for each format in a separate NodeJS process one-by-one (i.e. sequentially).

For each tested format, benchmark loads JS chunks one-by-one sequentially and measures:

  1. Time it takes to load every chunk
  2. Time it takes to read every graphql query in the chunk (using hardcoded function read defined separately for each tested format)

In the end, aggregated stats for each format includes:

  1. Total time it took to load all chunks
  2. An array of load time per chunk
  3. For each chunk: an array of read times per query
  4. Peak JS heap size, final JS heap size

Those aggregated results should be stored in ./results folder as JSON file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.