Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Speed up generation #336

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

apalm
Copy link

@apalm apalm commented Dec 7, 2018

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

@jasonkuhrt
Copy link
Member

jasonkuhrt commented Jan 1, 2019

@apalm thanks for this!

  • In perf: introduce benchmarks #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 jasonkuhrt self-requested a review January 1, 2019 14:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants