-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use goroutine about processing each array elements #316
Conversation
codegen/object.go
Outdated
{{.arr}} = append({{.arr}}, func() graphql.Marshaler { | ||
{{ .next }} | ||
}()) | ||
go func({{.index}} int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably avoid creating a new gofunc if:
- there is only one element in the array
- the child field doesn't have a resolver (accessing properties is cheap and should happen sequentially)
codegen/object.go
Outdated
@@ -212,28 +212,37 @@ func (f *Field) doWriteJson(val string, remainingMods []string, astType *ast.Typ | |||
} | |||
var arr = "arr" + strconv.Itoa(depth) | |||
var index = "idx" + strconv.Itoa(depth) | |||
var wg = "wg" + strconv.Itoa(depth) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this probably doesn't need to be nested, and can be shared by the whole field.
Don't worry about testing performance. It shouldn't be too hard to test that |
updated! |
codegen/object.go
Outdated
return {{.arr}}`, map[string]interface{}{ | ||
"val": val, | ||
"arr": arr, | ||
"index": index, | ||
"wg": wg, | ||
"top": depth == 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably can just go into WriteJson and be prefixed on? Doing it here in the recursive part is a bit hard to reason about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is little bit difficult.
We should exec wg.Wait()
before return statement.
https://github.com/99designs/gqlgen/pull/316/files#diff-3995ea1c8b08158971f7c289f7f7d50aR256
This really needs some tests :( |
|
…element use goroutine about processing each array elements
refs #313
#301 makes ResolverContext immutable.
We can use concurrent processing safety.
cc/ @dvic
I have:
performance regression test is so hard to writing... 🤔