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

FieldResolver performance #3945

Closed
sergey-shablenko opened this issue Aug 6, 2023 · 3 comments
Closed

FieldResolver performance #3945

sergey-shablenko opened this issue Aug 6, 2023 · 3 comments

Comments

@sergey-shablenko
Copy link

sergey-shablenko commented Aug 6, 2023

I have made few load tests using same logic with and without fields with FieldResolver
query with FieldResolver has 2x worse performance than without them
field resolvers I used are very simple ones

Any ideas why? How to improve?

query without field resolvers

query CoinTypes($page: Float!, $pageSize: Float!, $locale: SupportedLocales!) {  coinTypes(  page: $page  pageSize: $pageSize, locale: $locale) {  data {  id  idX  defaultCoin {  id  image {  id  url  __typename  }  __typename  }  __typename  }  total  __typename  } }

query with field resolvers

query CoinTypes($page: Float!, $pageSize: Float!, $locale: SupportedLocales!) {  coinTypes(  page: $page  pageSize: $pageSize, locale: $locale) {  data {  id  idX  ruler {  id  name(locale: $locale)  __typename  }  mint {  id  name(locale: $locale)  __typename  }  metal {  id  name(locale: $locale)  __typename  }  denomination {  id  name(locale: $locale)  __typename  }  state {  id  name(locale: $locale)  __typename  }  defaultCoin {  id  image {  id  url  __typename  }  __typename  }  __typename  }  total  __typename  } }
  @FieldResolver(() => GraphQLString, { name: 'name', nullable: true })
  async name(
    @Root() someEntity: SomeEntity,
    @Arg('locale', () => SupportedLocales) locale: SupportedLocales
  ): Promise<string> {
    return someEntity[`name${capitalize(locale)}`];
  }

results with field resolvers (4 of them)
image

results without field resolvers
image

@mwanjabala
Copy link

Depending on the scale a few more fields could result in a lot more function calls in the resolvers. That coupled with Node.js / JS single threaded nature might be problematic.

@yaacovCR
Copy link
Contributor

My apologies, but I am not seeing the exact lines in the numbers above where the 2x worse performance is demonstrated. That certainly does seem excessive. I am not sure if it is something that we can help with, but if you are able to set up a minimal reproduction using just vanilla graphql JS, that might help.

@yaacovCR
Copy link
Contributor

Closing for now, please feel free to reopen!

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

No branches or pull requests

4 participants
@yaacovCR @sergey-shablenko @mwanjabala and others