Skip to content

perf: implement request parsing result caching #192

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-t
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
jackson-core-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" }
caffeine = { module = "com.github.ben-manes.caffeine:caffeine", version = "3.2.0" }
aedile = { module = "com.sksamuel.aedile:aedile-core", version = "2.0.3" }
deferredJsonBuilder = { module = "com.apurebase:DeferredJsonBuilder", version = "1.0.0" }
ktor-server-core = { module = "io.ktor:ktor-server-core", version.ref = "ktor" }
ktor-server-auth = { module = "io.ktor:ktor-server-auth", version.ref = "ktor" }
Expand Down
8 changes: 7 additions & 1 deletion kgraphql/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ benchmark {
jmhVersion = "1.37"
}
}

configurations {
register("requestCachingBenchmark") {
include("com.apurebase.kgraphql.RequestCachingBenchmark")
}
}
}

dependencies {
Expand All @@ -34,7 +40,7 @@ dependencies {
implementation(libs.kotlinx.serialization.json)
implementation(libs.jackson.core.databind)
implementation(libs.jackson.module.kotlin)
implementation(libs.caffeine)
implementation(libs.aedile)
implementation(libs.deferredJsonBuilder)

testImplementation(libs.hamcrest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.util.concurrent.TimeUnit
@State(Scope.Benchmark)
@Warmup(iterations = 10)
@Measurement(iterations = 5)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@OutputTimeUnit(TimeUnit.SECONDS)
open class RequestCachingBenchmark {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is old code but it looks like this benchmark is primarily measuring the execution, not the parsing. Can we have a dedicated benchmark for parsing (as well), maybe with different kinds of requests?


@Param("true", "false")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.apurebase.kgraphql.function

import com.github.benmanes.caffeine.cache.Caffeine
import com.sksamuel.aedile.core.asLoadingCache
import kotlinx.coroutines.CoroutineScope

internal inline fun <X, Y> memoize(scope: CoroutineScope, memorySize: Long, crossinline f: suspend (X) -> Y): suspend (X) -> Y {
val cache = Caffeine
.newBuilder()
.maximumSize(memorySize)
.asLoadingCache<X, Y>(scope) { f(it) }

return { cache.get(it) }
}

This file was deleted.

Loading