Large type system does not compile. executionContext too large
- Dominant language
- Go
- Stars
- 10.8k
- Forks
- 1.3k
- Avg merge
- 2d 36m
- Merged PRs (30d)
- 26
Description
### What happened?
With very large type systems gqlgen can generate code that can no longer by compiled by the go compiler. Once more than 65.000 field marshaling methods have been added to the `executionContext` the Go compiler fails with:
```
:1: internal compiler error: too many methods on *executionContext:
```
In our case we hit that limit at 78.000 methods. We realize that running such a large type system is probably not efficient and also notice that the gqlgen compiler hasn't been optimized for this. It takes quite some time to generate the code because the generation is single threaded. While we are working on refactoring our approach we are blocked by this problem.
There is a simple fix since the majority of the methods on `executionContext` are field marshaling functions which are all private. Their number grows with the number of types **and** number of fields per type.
They can safely be converted to regular functions where the `*executionContext` is passed as an argument. Their names are unique and most likely won't collide with any existing function. And if that would be the case the internal function can be renamed.
In our case the number of methods went down from 78.000 to just 4.200.
We are currently testing this with v0.17.4 and will bump to the latest version soon.
The patch is rather small and can be found here: https://github.com/northvolt/gqlgen/commit/78b17868d0415cfe1c600d154d6f17ca2c8fb311
I will create a PR once we've moved to the latest released version.
Contributor guide
Assessment
This issue has not been assessed yet.