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

Recommendation: Benchmarks

Open j opened this issue 6 years ago • 5 comments

It'd be a good idea to have benchmarks against vanilla graphql-yoga plain resolvers. Perhaps keeping it simple and not including the extras of course. Just @Arg / @Context / @Root / @*Type decorators against vanilla graphql, etc.

Might make it easier to help optimize where needed or show the world that class mapping is actually beneficial (because I tried going back to vanilla graphql + manage my own schema and no object mapping and realized how much I enjoy using classes for defining schema)

j avatar May 02 '18 18:05 j

Building schema from class metadata has no impact on runtime performance. TypeGraphQL is just a wrapper on top of graphql-js reference implementation, as well as graphql-tools used by graphql-yoga.

Things like @arg / @context / @root also has no overhead, as well as simple (implicit) field resolvers. The only overhead is with additional features - handling middlewares stack, authorization, args validation, etc. The only difference might be with creating class instance of root object or args object (it's simple new with assign so no big custom logic like with class-transformer), you can check is src/resolvers that injecting params into methods is just a few simple helper func calls and if-s.

With simple hello world resolvers and simple args it might show some overhead but in real app when you have a lot of api/db calls, validation, authorization and other business logic, the overhead might be even not noticeable.

If you worry about the performance and CPU/RAM usage, it's better to switch to Golang for building microservices. Node.js simplicity and TypeGraphQL abstraction is for quick&easy development of apps 😉

MichalLytek avatar May 02 '18 18:05 MichalLytek

This one looks promissing: https://github.com/LiUGraphQL/LinGBM

@j If you've found other good performance benchmark for GraphQL server implementations, please share it here 😉

MichalLytek avatar Oct 04 '18 18:10 MichalLytek

Sorry, @19majkel94 saw that there was an issue relating to simple stuff. I too have the need for simple stuff in many cases. His example is on the ad side so latency is everything obviously and every ms counts. You stated that real life stuff needs to be benchmarked (db / http / etc), but I don't think that's the case. I think it should just be simple graphql queries that do raw things... So Object mapping, middlewares, etc.. Optimizations could def be in place in certain areas. I created a global middleware and it gets called 100s of times / request which IMO is already an optimization in itself. DB benchmarks (ORM/etc) could be in the repository on their own.

j avatar Mar 04 '19 19:03 j

A note to myself: consider using https://github.com/caderek/benny 😄

MichalLytek avatar Mar 22 '20 09:03 MichalLytek

There's a basic comparison here: https://github.com/benawad/node-graphql-benchmarks

re-thc avatar Jul 15 '20 15:07 re-thc