graphql-js icon indicating copy to clipboard operation
graphql-js copied to clipboard

FieldResolver performance

Open sergey-shablenko opened this issue 2 years ago • 1 comments

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

sergey-shablenko avatar Aug 06 '23 15:08 sergey-shablenko

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.

mwanjabala avatar Aug 16 '23 17:08 mwanjabala

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 avatar Mar 29 '24 07:03 yaacovCR

Closing for now, please feel free to reopen!

yaacovCR avatar Apr 11 '24 19:04 yaacovCR