99designs/gqlgen

High Memory Usage During Generation

开放

#2,981 创建于 2024年3月28日

 (5 条评论) (1 个反应) (0 位负责人)Go (1,250 个派生)auto 404
build-perfhelp wantedperformance

仓库指标

星标
 (10,737 个星标)
PR 合并指标
 (平均合并 11天) (30 天内合并 20 个 PR)

描述

What happened?

Running gqlgen in our project with a few hundred types can lead to >12 GB of memory usage on my local MacBook M2, as well as consuming a large portion of the CPU. It runs for ~1-2 minutes locally, but can take 5 minutes or longer (and event time out) in our CI pipelines, likely due to memory constraints.

This seems to be due to binding medium-to-large Go packages, either through autobind or specifically binding particular models.

If I run gqlgen with a tiny dummy GQL schema and no Go bindings, the process uses ~500 MB and finishes within a few seconds. However if I declare a type binding to a single medium-to-large Go package, the process requires 3-5GB depending on the package, and takes >10s. This is true even if I bind to a tiny Go package that happens to import one of the larger packages.

Our real project of course binds to a number of packages, so we see even greater memory usage.

What did you expect?

Much lower memory usage, faster generation times on memory constrained systems.

Minimal graphql.schema and models to reproduce

type Example {
  id: ID!
}

Simply specifying an autobind to one of our larger packages with this tiny schema causes the problem.

versions

  • go run github.com/99designs/gqlgen version v0.17.45
  • go version go version go1.21.8 darwin/arm64

贡献者指南