Skip to content

Commit

Permalink
[wip] continued labs/v5 work
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Gammon <sam@elide.dev>
  • Loading branch information
sgammon committed Mar 5, 2025
1 parent fb13068 commit 43eef1a
Show file tree
Hide file tree
Showing 39 changed files with 2,433 additions and 931 deletions.
38 changes: 38 additions & 0 deletions benchmarks/bench-graalvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ sourceSets.all {
resources.setSrcDirs(listOf("jmh/resources"))
}

allOpen {
annotation("org.openjdk.jmh.annotations.BenchmarkMode")
}

dependencies {
implementation(libs.kotlinx.benchmark.runtime)
implementation(libs.kotlinx.coroutines.test)
Expand Down Expand Up @@ -72,6 +76,11 @@ benchmark {
warmups = 5
iterations = 5
}
create("entry") {
include("EntryBenchmark")
warmups = 5
iterations = 5
}
}
targets {
register("main") {
Expand Down Expand Up @@ -109,6 +118,7 @@ tasks.withType(JMHTask::class).configureEach {
jvmArgsAppend.addAll(
listOf(
"-XX:+UnlockExperimentalVMOptions",
"-Djava.util.concurrent.ForkJoinPool.common.parallelism=1",
"-Djava.library.path=${javaLibPath.get()}",
),
)
Expand All @@ -126,5 +136,33 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach
jvmTarget = JvmTarget.fromTarget(javaLanguageVersion)
javaParameters = true
incremental = true
freeCompilerArgs.add("-Xskip-prerelease-check")
}
}

fun checkNatives() {
if (!File(nativesPath).exists()) {
error("Natives not found at $nativesPath; please run `./gradlew natives -Pelide.release=true`")
}
}

val projectRootPath: String = rootProject.layout.projectDirectory.asFile.absolutePath

tasks.withType<JavaExec>().configureEach {
doFirst {
checkNatives()
}
jvmArgs(
listOf(
"--enable-preview",
"--enable-native-access=ALL-UNNAMED",
"-XX:+UseG1GC",
"-XX:+UnlockExperimentalVMOptions",
"-XX:+UnlockExperimentalVMOptions",
"-XX:+TrustFinalNonStaticFields",
"-Djava.library.path=${javaLibPath.get()}",
"-Delide.disableStreams=true",
"-Delide.project.root=$projectRootPath",
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,75 @@
* License for the specific language governing permissions and limitations under the License.
*/

@file:Suppress("unused", "FunctionName")

package benchmarks.entry

import java.io.PrintStream
import java.util.concurrent.TimeUnit
import kotlinx.benchmark.Benchmark
import kotlinx.benchmark.BenchmarkMode
import kotlinx.benchmark.Mode
import kotlinx.benchmark.OutputTimeUnit
import kotlinx.benchmark.Scope
import kotlinx.benchmark.Setup
import kotlinx.benchmark.State
import kotlinx.benchmark.Warmup

/** Benchmarks for Elide's entrypoint and related DI loading. */
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@BenchmarkMode(Mode.AverageTime)
@State(Scope.Benchmark)
@Warmup(iterations = 10)
class EntryBenchmark {
companion object {
@JvmStatic var originalOut: PrintStream? = null
@JvmStatic var originalErr: PrintStream? = null
@JvmStatic val projectDir: String =
requireNotNull(System.getProperty("elide.project.root")) { "Please set -Delide.project.root" }

@JvmStatic val jsHello = "$projectDir/tools/scripts/hello.js"
@JvmStatic val tsHello = "$projectDir/tools/scripts/hello.ts"
}

@Setup fun patchStdout() {
System.setProperty("elide.disableStreams", "true")
originalOut = System.out
originalErr = System.err
System.setOut(PrintStream(object : PrintStream(originalOut) {
override fun println(x: Any?) {
// Do nothing
}
}))
System.setErr(PrintStream(object : PrintStream(originalErr) {
override fun println(x: Any?) {
// Do nothing
}
}))
}

@Setup fun unpatchStdout() {
System.setOut(originalOut)
System.setErr(originalErr)
}

@Benchmark fun help(): Int {
return elide.tool.cli.entry(arrayOf("--help"), installStatics = false)
}

@Benchmark fun exit(): Int {
return elide.tool.cli.entry(arrayOf("--exit"), installStatics = false)
}

@Benchmark fun js(): Int {
return elide.tool.cli.entry(arrayOf("run", jsHello), installStatics = false).also {
assert(it == 0)
}
}

@Benchmark fun ts(): Int {
return elide.tool.cli.entry(arrayOf("run", tsHello), installStatics = false).also {
assert(it == 0)
}
}
}
Loading

0 comments on commit 43eef1a

Please sign in to comment.