Skip to content

Add oshi-benchmark module with JMH benchmarks comparing JNA and FFM - #3127

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:oshi-benchmark
Apr 8, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:oshi-benchmark

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 8, 2026 •

Copy link
Copy Markdown
Member

Adds a new oshi-benchmark module (JDK 25+) providing JMH microbenchmarks to measure and compare the performance of JNA and FFM implementations side by side.

Changes

  • oshi-benchmark/pom.xml: New module depending on oshi-core-java25 as a compiled jar (same pattern as oshi-demo). Uses JMH 1.37, maven-shade-plugin to produce a self-contained benchmarks.jar, and skips OSGi/forbiddenapis/surefire plugins that don't apply. Compiler configured with useModulePath=false and explicit annotationProcessorPaths to work around a JPMS/JMH annotation processor incompatibility. Includes a TODO noting that oshi-core will need to be added as a second dependency once the FFM module is split from the JNA module.
  • oshi-benchmark/scripts/run-benchmarks.sh: Convenience script that auto-detects the repository root, builds the fat jar via ./mvnw if not already present, and runs the benchmarks. Accepts JMH arguments (e.g. a benchmark class name) as pass-through parameters.
  • ProcessesBenchmark.java: Side-by-side @Benchmark methods jna() and ffm() both calling getProcesses() on their respective OperatingSystem instances, initialized once in @Setup. Configured for 3 warmup × 2s and 5 measurement × 2s iterations, with --enable-native-access=ALL-UNNAMED embedded in @Fork so no extra JVM flags are needed at the command line.
  • config/checkstyle-suppressions.xml: Added suppression for [\\/]benchmark[\\/].* matching the existing demo suppression pattern.
  • pom.xml: Added oshi-benchmark to the java25 profile module list and to the enforcer's import exclusions.
  • Version bump: 6.11.2-SNAPSHOT → 6.12.0-SNAPSHOT across all poms, README, index.md, and CHANGELOG (minor bump reflecting the new module addition).

Initial benchmark results (macOS, JDK 25)

Benchmark Mode Score Error Units
ProcessesBenchmark.ffm avgt 11.202 ± 0.340 ms/op
ProcessesBenchmark.jna avgt 44.623 ± 3.695 ms/op

FFM is approximately 4× faster than JNA for getProcesses() on macOS.

Summary by CodeRabbit

  • New Features

    • Added a benchmark module with JMH benchmarks to compare JNA vs FFM implementations.
    • Added a convenience script to build and run benchmarks (requires Java 25+).
  • Chores

    • Bumped project version to 6.12.0-SNAPSHOT across the repository.
    • Updated documentation and download links to include the new benchmark and snapshot artifacts.

@coderabbitai

coderabbitai Bot commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fd1bde31-5404-45f0-b308-ca6d18c4dd38

📥 Commits

Reviewing files that changed from the base of the PR and between 08280f0 and df437f9.

📒 Files selected for processing (2)
  • oshi-benchmark/pom.xml
  • oshi-benchmark/scripts/run-benchmarks.sh
🚧 Files skipped from review as they are similar to previous changes (2)
  • oshi-benchmark/scripts/run-benchmarks.sh
  • oshi-benchmark/pom.xml
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Analyze (java)

📝 Walkthrough

Walkthrough

Adds an oshi-benchmark JMH module (Java 25) comparing JNA vs FFM for OperatingSystem#getProcesses(), bumps project/version references to 6.12.0-SNAPSHOT across POMs and docs, and includes scripts, checkstyle suppression, and changelog/readme/site updates.

Changes

Cohort / File(s) Summary
Version Bump (POM files)
pom.xml, oshi-core/pom.xml, oshi-core-java11/pom.xml, oshi-core-java25/pom.xml, oshi-demo/pom.xml, oshi-dist/pom.xml
Parent project version updated from 6.11.2-SNAPSHOT → 6.12.0-SNAPSHOT.
New Benchmark Module
oshi-benchmark/pom.xml, oshi-benchmark/src/main/java/oshi/benchmark/ProcessesBenchmark.java, oshi-benchmark/scripts/run-benchmarks.sh
Adds oshi-benchmark Maven module (JMH) targeting Java 25, shaded uberjar config, JMH benchmark class comparing JNA vs FFM, and a build/run script that checks Java ≥25 and builds/executes benchmarks.
Root project config
pom.xml
Adds oshi.benchmark.** to maven-enforcer RestrictImports exclusions and includes oshi-benchmark in the java25 profile module list.
Style checks
config/checkstyle-suppressions.xml
Adds suppression to ignore Checkstyle for files under benchmark directories.
Documentation & site
CHANGELOG.md, README.md, src/site/markdown/index.md
Updates download/Maven links to 6.12.0-SNAPSHOT, adds changelog "New Features" entry for PR #3127, and documents oshi-benchmark with usage/run instructions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐰 I sniff the code, a tiny hop and cheer,
Benchmarks bloom for FFM and JNA near,
Six-twelve dawns with Java twenty‑five flair,
I drum small paws and watch the numbers flare,
Hop on, run fast — performance in the air!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately summarizes the main change: adding a new oshi-benchmark module with JMH benchmarks that compare JNA and FFM implementations.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Apr 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.55%. Comparing base (8ad6340) to head (df437f9).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3127      +/-   ##
==========================================
+ Coverage   66.42%   67.55%   +1.13%     
==========================================
  Files          37       37              
  Lines        2034     2034              
  Branches      340      340              
==========================================
+ Hits         1351     1374      +23     
+ Misses        561      540      -21     
+ Partials      122      120       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
oshi-benchmark/scripts/run-benchmarks.sh (1)

22-26: Consider adding a Java 25 preflight check for clearer failures.

If run on older JDKs, Line 24/Line 25 can fail with reactor/module-selection errors; an early version check gives a direct message.

💡 Suggested preflight guard
 cd "${REPO_ROOT}"
 JAR="${REPO_ROOT}/oshi-benchmark/target/benchmarks.jar"
+
+JAVA_MAJOR="$(java -version 2>&1 | awk -F[\".] '/version/ {print $2}')"
+if [ "${JAVA_MAJOR}" -lt 25 ]; then
+    echo "ERROR: oshi-benchmark requires JDK 25+ (detected ${JAVA_MAJOR})." >&2
+    exit 1
+fi
 
 if [ ! -f "${JAR}" ]; then
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-benchmark/scripts/run-benchmarks.sh` around lines 22 - 26, Add a Java 25
preflight check at the top of run-benchmarks.sh before the existing JAR build
block (before the if [ ! -f "${JAR}" ] ... fi) to detect the runtime Java major
version (from java -version or $JAVA_HOME) and exit with a clear error if the
major version is less than 25; update the error message to reference the script
name and required Java 25 so users see a direct, actionable failure instead of
later reactor/module-selection errors when running the ./mvnw install/package
commands.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CHANGELOG.md`:
- Line 3: The "##### New Features" heading jumps levels and triggers MD001;
change that heading to the next level up (use "#### New Features") so it is one
level deeper than the release heading and no longer skips intermediate levels;
locate the "##### New Features" line and replace it with "#### New Features" to
satisfy markdownlint.

In `@oshi-benchmark/pom.xml`:
- Around line 100-102: Remove the unnecessary preview compiler argument by
deleting the <arg>--enable-preview</arg> entry inside the <compilerArgs> block
(the XML elements named compilerArgs and arg) in the Maven pom so the build no
longer passes --enable-preview to the compiler.

---

Nitpick comments:
In `@oshi-benchmark/scripts/run-benchmarks.sh`:
- Around line 22-26: Add a Java 25 preflight check at the top of
run-benchmarks.sh before the existing JAR build block (before the if [ ! -f
"${JAR}" ] ... fi) to detect the runtime Java major version (from java -version
or $JAVA_HOME) and exit with a clear error if the major version is less than 25;
update the error message to reference the script name and required Java 25 so
users see a direct, actionable failure instead of later reactor/module-selection
errors when running the ./mvnw install/package commands.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f550f9a0-c5af-45d8-b81c-87c26c0eb433

📥 Commits

Reviewing files that changed from the base of the PR and between c760ab0 and 08280f0.

📒 Files selected for processing (13)
  • CHANGELOG.md
  • README.md
  • config/checkstyle-suppressions.xml
  • oshi-benchmark/pom.xml
  • oshi-benchmark/scripts/run-benchmarks.sh
  • oshi-benchmark/src/main/java/oshi/benchmark/ProcessesBenchmark.java
  • oshi-core-java11/pom.xml
  • oshi-core-java25/pom.xml
  • oshi-core/pom.xml
  • oshi-demo/pom.xml
  • oshi-dist/pom.xml
  • pom.xml
  • src/site/markdown/index.md
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 11, ubuntu-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 25, ubuntu-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

  • oshi-core-java11/pom.xml
  • oshi-core-java25/pom.xml
  • src/site/markdown/index.md
  • README.md
  • pom.xml
  • oshi-benchmark/pom.xml
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.

Applied to files:

  • oshi-core-java11/pom.xml
  • oshi-core-java25/pom.xml
  • oshi-core/pom.xml
  • oshi-dist/pom.xml
  • src/site/markdown/index.md
  • README.md
  • pom.xml
  • oshi-benchmark/pom.xml
🪛 markdownlint-cli2 (0.22.0)
CHANGELOG.md

[warning] 3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h5

(MD001, heading-increment)

🔇 Additional comments (15)
config/checkstyle-suppressions.xml (1)

7-7: Benchmark suppression is consistent with existing policy.

This follows the same suppression model already used for demo and is appropriate for generated/experimental benchmark code paths.

oshi-core-java11/pom.xml (1)

8-8: Parent version bump looks correct.

This change cleanly aligns oshi-core-java11 with the new 6.12.0-SNAPSHOT baseline.

oshi-core-java25/pom.xml (1)

8-8: Version alignment is good here.

No concerns with updating the parent reference to 6.12.0-SNAPSHOT.

oshi-dist/pom.xml (1)

8-8: LGTM on parent version update.

This keeps oshi-dist aligned with the rest of the multi-module snapshot bump.

oshi-demo/pom.xml (1)

8-8: Parent snapshot bump is correct.

No issues with this module-level version alignment.

oshi-core/pom.xml (1)

8-8: Core module version bump is clean.

This is consistent with the repository-wide move to 6.12.0-SNAPSHOT.

CHANGELOG.md (1)

1-4: Release entry content is clear and correctly scoped.

The new 6.12.0 section and PR reference read well and match the feature being introduced.

src/site/markdown/index.md (2)

53-55: Snapshot links are correctly version-aligned.

These links now match the 6.12.0-SNAPSHOT project versioning.


118-122: Benchmark documentation addition looks good.

The new section is concise and gives a clear execution path for the JDK 25+ benchmark module.

README.md (2)

53-55: Snapshot version link update looks good.

The version bump to 6.12.0-SNAPSHOT is consistent and clear in this section.


118-122: Benchmark usage docs are clear and actionable.

The added benchmark description plus direct script invocation improves discoverability for the new module.

pom.xml (3)

7-7: Version bump is consistent.

This aligns the parent POM with the new snapshot baseline.


709-713: RestrictImports exclusion for benchmark package is correctly scoped.

This prevents false positives for JMH imports in benchmark sources while keeping restrictions intact elsewhere.


1000-1002: java25 profile module inclusion is correct.

Adding oshi-benchmark here matches the intended JDK 25+ build activation behavior.

oshi-benchmark/src/main/java/oshi/benchmark/ProcessesBenchmark.java (1)

44-69: Solid JMH benchmark structure for apples-to-apples comparison.

Setup scoping and paired benchmark methods are well-formed for comparing JNA vs FFM on the same API call.

Comment thread CHANGELOG.md Resolved
Comment thread oshi-benchmark/pom.xml Resolved
…ight check

- Remove unnecessary --enable-preview compiler arg from benchmark pom;
  no preview language features are used in ProcessesBenchmark
- Add Java 25 version check to run-benchmarks.sh before attempting to
  build or run, with a clear actionable error message
@dbwiddis
dbwiddis merged commit 000e5a0 into oshi:master Apr 8, 2026
14 checks passed
@dbwiddis
dbwiddis deleted the oshi-benchmark branch April 8, 2026 17:54
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