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

backport ExecutionPath.cacheKeyReversed #781

Merged
merged 1 commit into from
Nov 3, 2021

Conversation

yanns
Copy link
Contributor

@yanns yanns commented Nov 3, 2021

From #775
and #774

By using this in sangria-slow-logs, we will be able to generate much less objects.

From #775
and #774

By using this in sangria-slow-logs, we will be able to generate much less objects.
@yanns
Copy link
Contributor Author

yanns commented Nov 3, 2021

The code I'd like to optimize is the following one (from sangria-slow-logs):

    val path = even(ctx.path.cacheKey)

    queryVal.update(path, ctx.parentType.name, ctx.field.name, success, fieldVal, System.nanoTime())
  }

  def even[T](v: Vector[T]): Vector[T] = v.iterator.zipWithIndex
    .filter(_._2 % 2 == 0)
    .map(_._1)
    .toVector

This new "API" does not really help here.

@yanns yanns closed this Nov 3, 2021
@yanns
Copy link
Contributor Author

yanns commented Nov 3, 2021

Actually the reverse iterator can be helpful:

    val path = even(ctx.path.cacheKey.reverseIterator)

  private def even[T](v: Iterator[T]): Vector[T] = {
    val l = new _root_.scala.collection.mutable.ListBuffer[T]()
    var even = false
    while (v.hasNext) {
      val e = v.next()
      if (even) {
        l.prepend(e)
      }
      even = !even
    }
    l.toVector
  }

@yanns yanns reopened this Nov 3, 2021
@yanns yanns merged commit 1ddfee0 into main-2.x Nov 3, 2021
@yanns yanns deleted the backport_ExecutionPath_cacheKeyReversed branch November 3, 2021 08:22
yanns added a commit that referenced this pull request Nov 3, 2021
same API as in sangria 2.x: #781
It will allow to optimize sangria-slow-logs
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

Successfully merging this pull request may close these issues.

1 participant