Skip to content
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

Cleaner default resolver, cache FieldDefMap Get, preallocate #241

Closed
wants to merge 3 commits into from

Conversation

ajackson-cpi
Copy link
Contributor

Returning 26k rows for me was taking 8 seconds of post-Resolve() processing. I reduced that to 305ms by:

  • Returning the cached FieldDefMap (7 seconds)
  • Preallocating result map/array structures (5ms or so)
  • DefaultResolver logically identical, but far more efficient: uses reflect.FieldByName instead of checking in a loop. Allocates fewer variables.

@bbuck
Copy link
Collaborator

bbuck commented Aug 25, 2017

It might be worth building a lazy cache for different types as well, so we don't have to keep looping fields all the time. Maybe not as part of this PR (nice work) but just a general remark.

@edpark11
Copy link

edpark11 commented Apr 8, 2018

Thanks for writing this! An (admittedly large) graphql list query was taking 10s.
This piece in particular (returning the cached field definition map) resulted in a 8x speedup. Possible to accept that piece of the patch? The default resolver patch currently breaks against the master branch but the cached field definition (just 3 lines) works fine.

func (gt *Object) Fields() FieldDefinitionMap {                                      
  if len(gt.fields) != 0 {
    return gt.fields
  }

@ajackson-cpi
Copy link
Contributor Author

It looks like the latest master has brought equivalent changes. My performance evaluation shows it quite similar.

@chris-ramon
Copy link
Member

Thank you for given latest changes on master a try @ajackson-cpi! there was a similar optimization introduced by #265, a couple of opt. missing from this PR:

We might want to add those via a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants