Skip to content

Large type system does not compile. executionContext too large #2681

@magiconair

Description

@magiconair

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:

<autogenerated>:1: internal compiler error: too many methods on *executionContext: <some number>

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: northvolt@78b1786

I will create a PR once we've moved to the latest released version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions