-
Notifications
You must be signed in to change notification settings - Fork 21
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
Optimize Datasource-based queries #467
Optimize Datasource-based queries #467
Conversation
…tasource-optimizations-attempt-2 # Conflicts: # zio-query/shared/src/main/scala/zio/query/internal/BlockedRequests.scala
…tempt-2 # Conflicts: # zio-query/shared/src/main/scala/zio/query/CompletedRequestMap.scala # zio-query/shared/src/main/scala/zio/query/DataSource.scala
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Maybe try to run the caliban test suite as well to catch anything. Does it improve the caliban benchmarks too?
@ghostdogpr Doubtful, the optimizations are for datasource-backed queries and we only use |
I don't think we have anything in Caliban's test suites that uses datasources. I'll test it against some projects at $WORK (which heavily rely on ZQueries) when we have a snapshot version of zio-query and caliban |
This PR contains a series of optimizations aimed at improving the performance of Datasource-backed queries.
Main optimizations
Cache.Default
using ajava.util.ConcurrentHashMap[_, _]
in favour of aRef[Map[_, _]]
. This allows us to check if the cache provided is the default one, and if yes, use the "unsafe" methods to mutate the cache, reducing the number of flatmaps for eachZQuery.fromRequest
ZQuery.fromRequest
by using theFiberRef#getWith
methods forZQuery.currentCache
andZQuery.cachingEnabled
.BlockedRequests.run
using mutable datastructures and fulfilling promises unsafelyempty
constructor toCache
which allows pre-sizing the underlyingConcurrentHashMap
BlockedRequests.flatten
by using mutable datastructuresBenchmarking results:
Based on the newly added benchmarks, throughput is improved by:
series/2.x:
PR: