graphqlgen icon indicating copy to clipboard operation
graphqlgen copied to clipboard

Speed up generation

Open apalm opened this issue 5 years ago • 1 comments

I thought I'd open this PR for discussion.

Currently, running graphqlgen on a project with a large schema is very slow. For example, running graphqlgen on my project with a ~20,000 line schema takes over 2 minutes to complete.

I decided to do some quick profiling to figure out what was taking so long. To do this, I forked and cloned this repo, and then:

  1. In packages/graphqlgen, run yarn build
  2. cd into my project and run node --inspect PATH_TO_GRAPHQLGEN_DIST_INDEX_JS

Here's the result:

screen shot 2018-12-07 at 13 12 43

To my surprise, formatting the code in generateTypes was taking the vast majority of the time.

So, I decided to try disabling formatting the code in generateTypes. Here's the result after applying the diff and following the same steps from above:

screen shot 2018-12-07 at 13 11 13

This took ~4500 ms instead of ~160,000 ms, a vast improvement.

However, I doubt most projects have this large of a schema, and a formatted graphqlgen.ts is undeniably nicer to look at. Thoughts?

.zip of the .cpuprofiles: Archive.zip

apalm avatar Dec 07 '18 18:12 apalm

@apalm thanks for this!

  • In #372 we introduced a benchmark system
  • It would be great to add a currently-poorly-performing schema (+requisite models) to benchmarks, currently we're missing that
  • Can you share yours?

What I'm thinking next steps can be:

  1. update and commit benchmarks with an awful case such as yours
  2. follow up on your findings in this PR and see if we can drastically drop that number without losing the formatting

jasonkuhrt avatar Jan 01 '19 13:01 jasonkuhrt