Skip to content

Commit

Permalink
Refactor JNA bindings and update workflows
Browse files Browse the repository at this point in the history
Revised `LibLevelDB` to use direct mapping with `@JvmStatic` for improved performance and streamline code. Simplified and modularized GitHub Actions workflows, consolidating testing and benchmarking configurations. Added new JVM benchmarking support and fixed test configuration for better timeout handling.
  • Loading branch information
lamba92 committed Dec 13, 2024
1 parent 28f2f3b commit 13d32c0
Show file tree
Hide file tree
Showing 35 changed files with 1,304 additions and 1,214 deletions.
37 changes: 33 additions & 4 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
name: Benchmarks

on: [ push, pull_request ]
on:
pull_request:
push:
branches:
- master

jobs:
benchmarks:
jvm-benchmarks:
strategy:
matrix:
os: [ ubuntu, windows, macos ]
runs-on: ${{ matrix.os }}-latest
name: Benchmarks on ${{ matrix.os }}
name: "JVM / ${{ matrix.os }}"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand All @@ -17,7 +21,32 @@ jobs:
java-version: 21
- uses: gradle/actions/setup-gradle@v4
- run: chmod +x gradlew
- run: ./gradlew runBenchmark
- run: ./gradlew :benchmarks:jvmRun
env:
OPERATIONS_COUNT: 1000000
TEST_REPETITIONS: 10
- name: Append Table to Summary on Linux/macOS
if: runner.os != 'Windows'
run: cat benchmarks/build/benchmark/table.txt >> $GITHUB_STEP_SUMMARY
- name: Append Table to Summary on Windows
if: runner.os == 'Windows'
run: Get-Content benchmarks\build\benchmark\table.txt | ForEach-Object { Add-Content -Path $Env:GITHUB_STEP_SUMMARY -Value $_ }

native-benchmarks:
strategy:
matrix:
os: [ ubuntu, windows, macos ]
runs-on: ${{ matrix.os }}-latest
name: "Native / ${{ matrix.os }}"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: adopt
java-version: 21
- uses: gradle/actions/setup-gradle@v4
- run: chmod +x gradlew
- run: ./gradlew runNativeBenchmark
env:
OPERATIONS_COUNT: 1000000
TEST_REPETITIONS: 10
Expand Down
17 changes: 0 additions & 17 deletions .github/workflows/lint-check.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/native-tests.yml

This file was deleted.

38 changes: 28 additions & 10 deletions .github/workflows/jvm-tests.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
name: JVM tests
name: Tests

on: [ push, pull_request ]
on:
pull_request:
push:
branches:
- master

jobs:
lint:
runs-on: ubuntu-latest
name: linting
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: adopt
java-version: 21
- uses: gradle/actions/setup-gradle@v4
- run: chmod +x gradlew
# --no-build-cache because of https://github.com/JLLeitschuh/ktlint-gradle/issues/522#issuecomment-1843237381
- run: ./gradlew --no-build-cache ktlintCheck :buildSrc:ktlintCheck

android-tests:
continue-on-error: true
runs-on: ubuntu-latest
name: Android tests
name: android
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand Down Expand Up @@ -36,24 +54,24 @@ jobs:
name: tests-results-android
path: build/reports

jvm-tests:
tests:
continue-on-error: true
strategy:
matrix:
os: [ubuntu, windows, macos]
runs-on: ${{ matrix.os }}-latest
name: JVM tests on ${{ matrix.os }}
name: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: gradle/actions/setup-gradle@v4
- run: chmod +x gradlew
- uses: actions/setup-java@v4
with:
distribution: adopt
java-version: 21
- run: chmod +x gradlew
- uses: gradle/actions/setup-gradle@v4
- run: ./gradlew jvmTest
- run: ./gradlew allTests --stacktrace
- uses: actions/upload-artifact@v4
if: always()
with:
name: tests-results-${{ matrix.os }}
path: build/reports
name: tests-results-${{ matrix.os }}-${{ matrix.release == true && 'release' || 'debug' }}
path: build/reports
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ The library is available for:
- iOS (arm64, arm64-simulator, x64, x64-simulator)
- watchOS (arm64, arm64-simulator, x64-simulator)
- tvOS (arm64, arm64-simulator, x64-simulator)
- JVM (experimental, not stable AT ALL):
- JVM:
- Windows (x64, arm64)
- Linux (x64, arm64)
- macOS (x64, arm64)
- Android (arm64-v8a, armeabi-v7a, x86, x86_64)

No JS, sorry!
No JS or WASM, sorry!

LevelDB binaries are built in [lamba92/leveldb-builds](http://github.com/lamba92/leveldb-builds) repository.

Expand Down
69 changes: 39 additions & 30 deletions benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@file:OptIn(ExperimentalKotlinGradlePluginApi::class)

import org.gradle.internal.os.OperatingSystem
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import kotlin.io.path.absolutePathString
import kotlin.io.path.createDirectories
Expand All @@ -11,6 +14,11 @@ plugins {

kotlin {

jvm {
mainRun {
mainClass = "com.github.lamba92.leveldb.benchmarks.MainKt"
}
}
mingwX64()
linuxX64()
macosArm64()
Expand Down Expand Up @@ -43,42 +51,43 @@ tasks {
.asFile
.absolutePath

val jsonOutputPath =
layout.buildDirectory
.file("benchmark/data.json")
.get()
.asFile
.toPath()
.apply { parent.createDirectories() }
.absolutePathString()

val tableOutputPath =
layout.buildDirectory
.file("benchmark/table.txt")
.get()
.asFile
.toPath()
.apply { parent.createDirectories() }
.absolutePathString()

withType<Exec> {
environment("DB_PATH", dbPath)
environment(
"JSON_OUTPUT_PATH",
layout.buildDirectory
.file("benchmark/data.json")
.get()
.asFile
.toPath()
.apply { parent.createDirectories() }
.absolutePathString(),
)
environment(
"TABLE_OUTPUT_PATH",
layout.buildDirectory
.file("benchmark/table.txt")
.get()
.asFile
.toPath()
.apply { parent.createDirectories() }
.absolutePathString(),
)
environment("JSON_OUTPUT_PATH", jsonOutputPath)
environment("TABLE_OUTPUT_PATH", tableOutputPath)
}
register("runBenchmark") {
val mode =
when (project.properties["leveldb.release"]) {
null, "true" -> "Release"
"false" -> "Debug"
else -> error("Unknown value for leveldb.release")
}

withType<JavaExec> {
environment("DB_PATH", dbPath)
environment("JSON_OUTPUT_PATH", jsonOutputPath)
environment("TABLE_OUTPUT_PATH", tableOutputPath)
}

register("runNativeBenchmark") {
val os = OperatingSystem.current()
val task =
when {
os.isWindows -> "run${mode}ExecutableMingwX64"
os.isMacOsX -> "run${mode}ExecutableMacosArm64"
os.isLinux -> "run${mode}ExecutableLinuxX64"
os.isWindows -> "runReleaseExecutableMingwX64"
os.isMacOsX -> "runReleaseExecutableMacosArm64"
os.isLinux -> "runReleaseExecutableLinuxX64"
else -> error("Unknown OS ${os.name}")
}
dependsOn(task)
Expand Down
Loading

0 comments on commit 13d32c0

Please sign in to comment.