99designs / 99designs/gqlgen

Large type system does not compile. executionContext too large

Ouverte
#2,681 7 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Go
Étoiles
10.8k
Forks
1.3k
Merge moyen
2 j 36 min
PR mergées (30 j)
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.

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

L’issue concerne le code généré dans gqlgen, où les méthodes de marshaling des champs sur executionContext dépassent la limite du compilateur Go. La correction consiste à convertir ces méthodes en fonctions autonomes qui prennent *executionContext comme argument. Consultez le patch lié dans l’issue pour comprendre les changements nécessaires dans la logique de génération de code. Commencez par examiner le package codegen, en particulier les templates servant à générer les fonctions de marshaling des champs. Testez en générant un schéma volumineux afin de vérifier que l’erreur du compilateur est résolue.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
go
Domaine
compilers
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.