-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Parser micro-optimizations * Use flatMap instead of positive-lookahead * Add back nowarn annotations * Revert change to `definition` * Remove blackhole usage from parser benchmarks
- Loading branch information
1 parent
76e95b3
commit c849e0e
Showing
6 changed files
with
116 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,41 @@ | ||
package caliban | ||
|
||
import caliban.parsing.Parser | ||
import cats.effect.IO | ||
import io.circe.Json | ||
import caliban.parsing.adt.Document | ||
import cats.data.NonEmptyList | ||
import cats.parse.Caret | ||
import gql.parser.QueryAst | ||
import grackle.Operation | ||
import org.openjdk.jmh.annotations._ | ||
import sangria.execution._ | ||
import sangria.marshalling.circe._ | ||
import sangria.parser.QueryParser | ||
|
||
import java.util.concurrent.TimeUnit | ||
import scala.concurrent.duration._ | ||
import scala.concurrent.{ Await, ExecutionContextExecutor, Future } | ||
import scala.concurrent.ExecutionContextExecutor | ||
|
||
@State(Scope.Thread) | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@Warmup(iterations = 5, time = 3, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = 5, time = 3, timeUnit = TimeUnit.SECONDS) | ||
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) | ||
@Fork(1) | ||
class ParserBenchmark { | ||
import ComplexQueryBenchmark._ | ||
|
||
implicit val executionContext: ExecutionContextExecutor = scala.concurrent.ExecutionContext.global | ||
|
||
@Benchmark | ||
def runCaliban(): Unit = { | ||
val io = Parser.parseQuery(fullIntrospectionQuery) | ||
Caliban.run(io) | ||
() | ||
} | ||
def runCaliban(): Document = | ||
Parser.parseQueryEither(fullIntrospectionQuery).fold(throw _, identity) | ||
|
||
@Benchmark | ||
def runSangria(): Unit = { | ||
val future = Future.fromTry(QueryParser.parse(fullIntrospectionQuery)) | ||
Await.result(future, 1.minute) | ||
() | ||
} | ||
def runSangria(): sangria.ast.Document = | ||
QueryParser.parse(fullIntrospectionQuery).fold(throw _, identity) | ||
|
||
@Benchmark | ||
def runGrackle(): Unit = { | ||
Grackle.compiler.compile(fullIntrospectionQuery) | ||
() | ||
} | ||
def runGrackle(): Operation = | ||
Grackle.compiler.compile(fullIntrospectionQuery).getOrElse(throw new Throwable("Grackle failed to parse query")) | ||
|
||
@Benchmark | ||
def runGql(): Unit = { | ||
gql.parser.parseQuery(fullIntrospectionQuery) | ||
() | ||
} | ||
def runGql(): NonEmptyList[QueryAst.ExecutableDefinition[Caret]] = | ||
gql.parser.parseQuery(fullIntrospectionQuery).fold(e => throw new Throwable(e.prettyError.value), identity) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters