-
Notifications
You must be signed in to change notification settings - Fork 221
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
less allocation in ExecutionPath.add #769
Conversation
@agourlay WDYT? |
@@ -4,33 +4,35 @@ import sangria.marshalling.ResultMarshaller | |||
import sangria.ast | |||
import sangria.schema.ObjectType | |||
|
|||
case class ExecutionPath private (path: Vector[Any], cacheKeyPath: ExecutionPath.PathCacheKey) { | |||
class ExecutionPath private (_path: List[Any], cacheKeyPath: ExecutionPath.PathCacheKey) { | |||
lazy val path: List[Any] = _path.reverse |
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.
We could expose a Vector
here to have less breaking changes.
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.
If we never use the indexing aspect of the Vector
, I vote for getting rid of it if we can have breaking changes.
case s: String => m.scalarNode(s, "String", Set.empty) | ||
case i: Int => m.scalarNode(i, "Int", Set.empty) | ||
}) | ||
}.toVector) |
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.
Maybe it's faster to reverse a Vector
than a List
.
To avoid the |
a mutable List could be a better choice In the immutable world, cats Chain would be a good fit, but we should not add cats as a dependency. |
Thanks a lot for tackling this issue 👍
what is the thread safety story here for this class?
yes the
in both cases you could use |
Also a |
|
||
/** @return | ||
* last index in the path, if available | ||
*/ | ||
def lastIndex: Option[Int] = path.lastOption.collect { case i: Int => i } | ||
def lastIndex: Option[Int] = _path.headOption.collect { case i: Int => i } | ||
|
||
/** @return | ||
* the size of the path excluding the indexes | ||
*/ | ||
def size = cacheKeyPath.size / 2 |
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.
ideally the cacheKeyPath.size
should be cached as it is O(n) on a List
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.
Not sure about the performance when iterating on all elements.
and we would need to use |
I don't think we have concurrency update / access on it.
👍 |
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.
This looks like a clear improvement to me!
🐑
One way to fix #768
The issue with that approach is the usage of
reverse
that builds a newList
.