99designs / 99designs/gqlgen

Large type system does not compile. executionContext too large

Đang mở
#2,681 7 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Go
Star
10.8k
Fork
1.3k
Merge trung bình
2 ngày 36 phút
Pull request đã merge (30 ngày)
26

Mô tả

### 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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Issue này nói về mã được tạo trong gqlgen, trong đó các phương thức marshaling trường trên executionContext vượt quá giới hạn của trình biên dịch Go. Cách sửa là chuyển các phương thức này thành các hàm độc lập nhận *executionContext làm đối số. Hãy xem patch được liên kết trong issue để hiểu những thay đổi cần thiết trong logic tạo mã. Bắt đầu bằng cách kiểm tra package codegen, đặc biệt là các template dùng để tạo các hàm marshaling trường. Kiểm thử bằng cách tạo một schema lớn để xác minh rằng lỗi trình biên dịch đã được giải quyết.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
go
Lĩnh vực
compilers
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.