Skip to content

[Performance & Security] Dramatic Performance Regression from 0.11.7 to 14.5.8 #2428

Closed
@CreatCodeBuild

Description

@CreatCodeBuild

Reporting issues with GraphQL.js

I was using 0.11.7 and recently updated to 14.5.8. The performance of GraphQL layer decreased by about 60%.

Here is an example

const { graphql, buildSchema } = require('graphql');

const s = buildSchema(`

type Query {
    getX: [X]
    getY: [Y]
}

type X {
    name: String
    y: [Y]
}

type Y {
    name: String
    age: Int
    y: [Y]
}

`);
const stat = [];
for (let i = 0; i < 100 / 200 / 300 / 400; i++) {
    const t = new Date();
    const p = graphql(
        s,
        `{
        getX {
            name
            y {
                name, age
            }
        }
        getY {
            name
            age
            y { 
                name, age 
                y {
                    y {
                        name, age
                        y {
                            y {
                                y {
                                    name, y {
                                        y {
                                            name, age
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
      }`,
        {
            getX: () => {
                return [
                    X(),
                    X(),
                    X(),
                    X(),
                    X(),
                ]
            },
            getY: () => {
                return [Y(), Y(), Y()]
            }
        },                 // root value
    )
    const t2 = new Date();
    stat.push(t2 - t);
}

console.log( stat.reduce((sum, cur) => { return sum + cur}) / stat.length );

function X() {
    return {
        name: "X",
        y: function () {
            return [Y(), Y(), Y()]
        }
    }
}

function Y() {
    return {
        name: "Y",
        age: 200,
        y: function () {
            return [Y(), Y(), Y()];
        }
    }
}

Notice that I am not measuring the time when the promise is resolved. I am only measuring the time spent in the synchronous code that creates the promise.

I ran it N * 100 times in a loop. Here is the average in ms.

100 200 300 400
0.11.7 32.6 39.54 63.58 JavaScript heap out of memory
14.5.8 58.9 58.475 58.403 58.19

2 surprising find out:

  1. 0.11.7 has a memory leak
  2. 14.5.8's performance is more consistent but it is about 60% slower when running 100 times in a loop.

Of course, in a real scenario, the amount of traffic would be as fast as a for loop so that I never get this heap dump error in production.

My question are:

  1. Does anybody have any advice on how to improve the synchronous code performance? Should I upgrade to a newer version?
  2. Could the performance be related to the memory leak? For example, 0.11.7 leaks memory so that GC doesn't kick in so often such that it performs better in low traffic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions