Repository navigation
Use strings.Builder for querybuilder marshal method - #5008
Conversation
bef2d27 to
3c0bb1c
Compare
cpuguy83
left a comment
There was a problem hiding this comment.
Really nice speedup!
It seems like this is creating a strings.Builder for cases that it is not required, though (maybe the compiler optimizes that out?).
I also wonder if MarshalGQL could pass down a *strings.Builder to marshalValue and just have marshalValue use that recursively?
99a2823 to
7bbabea
Compare
That sounds good, I've tackled the first one on 7bbabea92859a4cc73b7f5613894906ed3626754 👍 The second idea sounds interesting too, will do some exploration and perhaps do another PR. |
31bb7a9 to
a2c61d5
Compare
Signed-off-by: Matias Insaurralde <[email protected]>
…er types Signed-off-by: Matias Insaurralde <[email protected]>
Signed-off-by: Matias Insaurralde <[email protected]>
a2c61d5 to
9c7a604
Compare
vito
left a comment
There was a problem hiding this comment.
LGTM, but curious if @aluzzardi has insight into the parallel marshaling we were doing before
| return v.String(), nil | ||
| } | ||
| return fmt.Sprintf("%q", v.String()), nil //nolint:gosimple,staticcheck | ||
| return strconv.Quote(v.String()), nil |
There was a problem hiding this comment.
Huh, I didn't realize we were just quoting Go strings to pass them to GraphQL - it seems like that could fail someday if they have different escape syntax, but I haven't found a way to break it yet, so 🤷♂️ guess it's fine
There was a problem hiding this comment.
Right -- those should be escaped. Impressed this worked for so long.
| eg, gctx := errgroup.WithContext(ctx) | ||
| for i := 0; i < n; i++ { | ||
| i := i | ||
| eg.Go(func() error { |
There was a problem hiding this comment.
Interesting that we did these in parallel before, perhaps a micro-optimization but I wonder if there were cases where it helped.
There was a problem hiding this comment.
Sorry, totally missed this comment.
It's because of "pass by object".
When passing a *Container type, there's a custom marshaller doing the *Container --> ContainerID conversion which issues an API call: https://github.com/dagger/dagger/blob/main/sdk/go/api.gen.go#L79
The problem is worsened since this is a recursive: passing an array with 10 elements, each containing a struct with 10 fields will result in 100 sequential API calls. On the upside, I don't think the API currently has a scenario where that is possible.
There are two layers of parallelism:
querybuilder.go:marshalArguments(): For a given GraphQL call, process all arguments in parallel (e.g. if chaining 10 things -- take all passed arguments and resolve them at once)- this code: for each argument, resolve each slice and struct elements in parallel
Combined they make sure that all *Object->ObjectID resolution happens in parallel
There was a problem hiding this comment.
@aluzzardi Ah - I didn't appreciate that marshaling involves sending an API request, that makes sense. Sounds important; will revert and reopen.
|
Any other changes required before this gets merged? Would love to see this in by the end of this week. Thanks for another fine improvement @matiasinsaurralde 💪 |
|
Will go ahead and merge - can't imagine dropping the parallel marshaling would have a huge impact, and the string escaping issue already existed before. Thanks again! |
Refactor
marshalto use an approach similar to #5007.Given this benchmark:
Running with the following command:
And comparing
mainto this branch, withbenchstat:benchcmpoutput: