Skip to content

Add JMH benchmarks for CPU ticks, memory, file stores, and network interfaces - #3184

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:add-benchmarks
Apr 22, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:add-benchmarks

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 22, 2026 •

Copy link
Copy Markdown
Member

Adds four new JMH benchmark classes comparing JNA vs FFM implementations:

  • CpuTicksBenchmark — getProcessorCpuLoadTicks() (2D array)
  • MemoryBenchmark — getAvailable(), getSwapTotal(), getSwapUsed()
  • FileStoreBenchmark — OSFileStore.updateAttributes() per store
  • NetworkIFBenchmark — NetworkIF.updateAttributes() per interface

All benchmarks disable memoization (oshi.util.memoizer.expiration=0) so they measure actual native call overhead rather than cache hits.

Benchmarks run on JDK 25 at the end of CI on all platforms with abbreviated iterations (-wi 1 -i 3 -f 1).

Also:

  • Fix stale oshi-core-java25 reference in run-benchmarks.sh
  • Suppress shade plugin's dependency-reduced-pom.xml generation

Summary by CodeRabbit

  • New Features

    • Added performance benchmarks to compare implementations for CPU ticks, file stores, memory, and network interfaces.
  • Chores

    • CI workflows updated to run benchmarks on JDK 25.
    • Benchmark packaging behavior adjusted to ensure a runnable shaded artifact.
    • Benchmark bootstrap improved to build required modules when the artifact is absent.

@coderabbitai

coderabbitai Bot commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds four JMH benchmark classes (CPU, file store, memory, network), updates oshi-benchmark packaging and run script, and adds JDK‑25‑only CI steps (Linux/macOS/Windows/PR workflows) that build and execute the benchmarks jar with JMH options. (≤50 words)

Changes

Cohort / File(s) Summary
CI Workflow Updates
.github/workflows/linux.yaml, .github/workflows/macos.yaml, .github/workflows/pr.yaml, .github/workflows/windows.yaml
Added a JDK‑25‑only CI step that builds oshi-benchmark (./mvnw package -DskipTests -Dshade.phase=package), then runs oshi-benchmark/target/benchmarks.jar with JMH args -wi 1 -i 3 -f 1 (conditions restricted to matrix.java containing 25).
Benchmark Module Config & Script
oshi-benchmark/pom.xml, oshi-benchmark/scripts/run-benchmarks.sh
Set <createDependencyReducedPom>false</createDependencyReducedPom> in maven‑shade-plugin; adjusted bootstrap install list to include oshi-common, oshi-core, oshi-core-ffm when the benchmarks jar is missing.
JMH Benchmark Classes
oshi-benchmark/src/main/java/oshi/benchmark/CpuTicksBenchmark.java, oshi-benchmark/src/main/java/oshi/benchmark/FileStoreBenchmark.java, oshi-benchmark/src/main/java/oshi/benchmark/MemoryBenchmark.java, oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java
Added four benchmark classes that set GlobalConfig.OSHI_UTIL_MEMOIZER_EXPIRATION=0, instantiate JNA and FFM implementations, provide @Benchmark methods plus main(...) runners to compare JNA vs FFM behavior and performance.

Sequence Diagram(s)

sequenceDiagram
  participant GH as GitHub Actions
  participant Maven as ./mvnw
  participant BenchJar as benchmarks.jar
  participant JMH as JMH Runner
  participant JNA as oshi.SystemInfo (JNA)
  participant FFM as oshi.ffm.SystemInfo (FFM)

  GH->>Maven: package oshi-benchmark (-DskipTests -Dshade.phase=package)
  Maven-->>GH: benchmarks.jar produced
  GH->>BenchJar: java -jar benchmarks.jar (JMH args)
  BenchJar->>JMH: start selected benchmarks
  JMH->>JNA: call CentralProcessor / Hardware / Memory / NetworkIF methods
  JMH->>FFM: call CentralProcessor / Hardware / Memory / NetworkIF methods
  JMH-->>BenchJar: aggregated results
  BenchJar-->>GH: exit (benchmarks complete)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • rohan-coder02

Poem

⚖️ Two runtimes face the score,
JNA and FFM stride the floor,
CPU, disk, memory, net — they test,
Java 25 sees who runs best,
Benchmarks hum; we watch, then store. 🚀

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: adding four JMH benchmark classes for CPU ticks, memory, file stores, and network interfaces.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
✨ 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 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.37%. Comparing base (56a7d95) to head (4970f29).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3184      +/-   ##
==========================================
- Coverage   57.38%   57.37%   -0.01%     
==========================================
  Files         421      421              
  Lines       20272    20272              
  Branches     3563     3563              
==========================================
- Hits        11634    11632       -2     
- Misses       6876     6878       +2     
  Partials     1762     1762              
Flag Coverage Δ
linux 22.55% <ø> (-0.01%) ⬇️
macos 25.77% <ø> (-0.01%) ⬇️
windows 34.84% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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: 5

🧹 Nitpick comments (1)
oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java (1)

51-63: Clarify that one JMH operation updates the full interface list.

us/op currently means “update all cached interfaces,” not “update one interface.” If JNA and FFM discover different counts, the comparison is skewed by list length; consider either reporting the counts or renaming/documenting this as an all-interfaces benchmark.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java` around
lines 51 - 63, Benchmark methods jna and ffm currently loop over the entire
lists jnaIfs and ffmIfs so each JMH operation measures "update all cached
interfaces" rather than a single interface; modify the benchmark to make this
explicit by either (a) renaming the methods to jna_updateAllInterfaces and
ffm_updateAllInterfaces (and update any JMH `@BenchmarkMode/benchmark` names) or
(b) add a short in-method comment and a thrown-away measurement that records the
sizes of jnaIfs and ffmIfs (e.g., consume jnaIfs.size() / ffmIfs.size() via the
Blackhole) so the output documents list lengths; ensure you reference the
methods jna and ffm and the fields jnaIfs, ffmIfs and the call to
updateAttributes() when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/linux.yaml:
- Around line 78-82: The JMH Benchmarks CI step runs "./mvnw package -pl
oshi-benchmark ..." without building upstream modules, causing resolution
failures for oshi-common, oshi-core, and oshi-core-ffm on a clean runner; update
the JMH Benchmarks step (the run command that invokes "./mvnw package -pl
oshi-benchmark -DskipTests -Dshade.phase=package -q") to include "-am" so Maven
will also build required modules (assemble modules) for the oshi-benchmark
invocation.

In @.github/workflows/macos.yaml:
- Around line 54-58: The JMH Benchmarks step ("JMH Benchmarks (JNA vs FFM)")
runs a fresh Maven invocation for only oshi-benchmark which can fail to resolve
in-repo snapshot modules; update the mvnw package command used there to build
dependent modules in the same reactor by adding the -am flag to the invocation
(i.e., ensure the ./mvnw package -pl oshi-benchmark command includes -am so
modules like oshi-common, oshi-core, and oshi-core-ffm are built).

In @.github/workflows/pr.yaml:
- Around line 74-78: The PR benchmark job "JMH Benchmarks (JNA vs FFM)" runs
Maven with -pl oshi-benchmark but doesn't build required reactor modules,
causing missing local snapshots; update the mvn invocation in that job (the
./mvnw package -pl oshi-benchmark ... command) to include -am so Maven builds
required modules alongside the benchmark module, ensuring the benchmark run is
self-contained.

In @.github/workflows/windows.yaml:
- Around line 50-54: The Maven step "JMH Benchmarks (JNA vs FFM)" currently runs
"./mvnw package -pl oshi-benchmark -DskipTests -Dshade.phase=package -q" which
fails to build required in-repo modules on a clean runner; modify that command
to include the -am (also-make) flag so it becomes "./mvnw package -pl
oshi-benchmark -am -DskipTests -Dshade.phase=package -q" to ensure oshi-common,
oshi-core and oshi-core-ffm are built and available for the benchmark jar
resolution.

In `@oshi-benchmark/src/main/java/oshi/benchmark/FileStoreBenchmark.java`:
- Around line 43-49: In FileStoreBenchmark.setup(), before creating any
oshi.SystemInfo instances, disable OSHI memoization by setting the JVM property
"oshi.util.memoizer.expiration" to "0" (e.g., via System.setProperty) so that
jnaOs and ffmOs created in setup() will not return cached/memoized file-store
data; ensure the System.setProperty call occurs at the top of setup() before new
oshi.SystemInfo() is invoked.

---

Nitpick comments:
In `@oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java`:
- Around line 51-63: Benchmark methods jna and ffm currently loop over the
entire lists jnaIfs and ffmIfs so each JMH operation measures "update all cached
interfaces" rather than a single interface; modify the benchmark to make this
explicit by either (a) renaming the methods to jna_updateAllInterfaces and
ffm_updateAllInterfaces (and update any JMH `@BenchmarkMode/benchmark` names) or
(b) add a short in-method comment and a thrown-away measurement that records the
sizes of jnaIfs and ffmIfs (e.g., consume jnaIfs.size() / ffmIfs.size() via the
Blackhole) so the output documents list lengths; ensure you reference the
methods jna and ffm and the fields jnaIfs, ffmIfs and the call to
updateAttributes() when making the change.
🪄 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: d2eb6c0b-ff91-4e6a-9596-bf3f113a0199

📥 Commits

Reviewing files that changed from the base of the PR and between 56a7d95 and f055752.

📒 Files selected for processing (10)
  • .github/workflows/linux.yaml
  • .github/workflows/macos.yaml
  • .github/workflows/pr.yaml
  • .github/workflows/windows.yaml
  • oshi-benchmark/pom.xml
  • oshi-benchmark/scripts/run-benchmarks.sh
  • oshi-benchmark/src/main/java/oshi/benchmark/CpuTicksBenchmark.java
  • oshi-benchmark/src/main/java/oshi/benchmark/FileStoreBenchmark.java
  • oshi-benchmark/src/main/java/oshi/benchmark/MemoryBenchmark.java
  • oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java
📜 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). (12)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, ubuntu-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:43.529Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
📚 Learning: 2026-04-06T04:45:51.516Z
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:51.516Z
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-benchmark/scripts/run-benchmarks.sh
📚 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-benchmark/scripts/run-benchmarks.sh
📚 Learning: 2026-04-18T03:18:03.725Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).

Applied to files:

  • oshi-benchmark/src/main/java/oshi/benchmark/CpuTicksBenchmark.java
  • oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java
  • oshi-benchmark/src/main/java/oshi/benchmark/MemoryBenchmark.java
  • oshi-benchmark/src/main/java/oshi/benchmark/FileStoreBenchmark.java
📚 Learning: 2026-04-19T01:28:43.529Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:43.529Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.

Applied to files:

  • oshi-benchmark/src/main/java/oshi/benchmark/CpuTicksBenchmark.java
  • oshi-benchmark/src/main/java/oshi/benchmark/MemoryBenchmark.java
📚 Learning: 2026-04-17T23:43:33.461Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

  • oshi-benchmark/src/main/java/oshi/benchmark/MemoryBenchmark.java
🔇 Additional comments (5)
oshi-benchmark/src/main/java/oshi/benchmark/MemoryBenchmark.java (3)

36-56: LGTM — benchmark configuration and setup are consistent.

The memoizer override is applied before constructing both JNA and FFM memory objects, which keeps this benchmark focused on native-call overhead.


58-70: LGTM — the JNA and FFM benchmark bodies are symmetric.

Both paths consume the same GlobalMemory / VirtualMemory calls, so the side-by-side measurement is fair.


72-75: LGTM — standalone JMH entry point is scoped to this benchmark.

oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java (2)

65-68: LGTM — standalone JMH entry point is scoped to this benchmark.


43-49: No memoizer override needed for NetworkIF benchmarks.

The concern about memoization caching doesn't apply here. While AbstractNetworkIF memoizes VM MAC address properties, the benchmark only calls updateAttributes(), which performs direct native I/O without accessing the memoized supplier. Unlike MemoryBenchmark's getAvailable() method, NetworkIF.updateAttributes() implementations (across all platforms) don't invoke any memoized code paths.

			> Likely an incorrect or invalid review comment.

Comment thread .github/workflows/linux.yaml Resolved
Comment thread .github/workflows/macos.yaml Resolved
Comment thread .github/workflows/pr.yaml Resolved
Comment thread .github/workflows/windows.yaml Resolved

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@oshi-benchmark/src/main/java/oshi/benchmark/FileStoreBenchmark.java`:
- Around line 53-65: The jna and ffm benchmarks currently iterate over all
discovered stores (jnaStores and ffmStores) so the measured time is for "all
stores" rather than per-store; either rename the benchmark methods to indicate
"allStores" (e.g., jnaAllStores / ffmAllStores) to clarify reporting, or change
the benchmark to operate on a single store per invocation by selecting one store
(use a `@Setup` to pick a fixed index or a `@Param` for store index or use
ThreadLocalRandom to pick an index) and update jna and ffm to call
updateAttributes() on only that one store (ensure jnaStores and ffmStores remain
available for selection).

In `@oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java`:
- Around line 53-65: The benchmark methods jna and ffm currently measure one JMH
invocation across all discovered interfaces (iterating jnaIfs and ffmIfs), which
can mislead readers into thinking times are per-interface; either rename the
methods to clarify they measure "all interfaces" (e.g., jnaAllInterfaces,
ffmAllInterfaces) or change the benchmark to update exactly one interface per
invocation by selecting a single NetworkIF from jnaIfs/ffmIfs (use a stable
selector like ThreadLocal/AtomicInteger modulo the list size or
ThreadLocalRandom) and call updateAttributes() on that single element so results
reflect per-interface timing. Ensure you update the benchmark method names and
JMH annotations or the selection logic consistently for both jna and ffm.
🪄 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: d9f21cb2-bc61-43c2-9166-2ce2c3a122fd

📥 Commits

Reviewing files that changed from the base of the PR and between f055752 and f4968b3.

📒 Files selected for processing (10)
  • .github/workflows/linux.yaml
  • .github/workflows/macos.yaml
  • .github/workflows/pr.yaml
  • .github/workflows/windows.yaml
  • oshi-benchmark/pom.xml
  • oshi-benchmark/scripts/run-benchmarks.sh
  • oshi-benchmark/src/main/java/oshi/benchmark/CpuTicksBenchmark.java
  • oshi-benchmark/src/main/java/oshi/benchmark/FileStoreBenchmark.java
  • oshi-benchmark/src/main/java/oshi/benchmark/MemoryBenchmark.java
  • oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java
✅ Files skipped from review due to trivial changes (2)
  • oshi-benchmark/pom.xml
  • .github/workflows/windows.yaml
🚧 Files skipped from review as they are similar to previous changes (5)
  • .github/workflows/linux.yaml
  • .github/workflows/pr.yaml
  • oshi-benchmark/scripts/run-benchmarks.sh
  • oshi-benchmark/src/main/java/oshi/benchmark/CpuTicksBenchmark.java
  • .github/workflows/macos.yaml
📜 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). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (3)
oshi-benchmark/src/main/java/oshi/benchmark/FileStoreBenchmark.java (1)

44-50: Memoization setup is in the right place.

GlobalConfig.OSHI_UTIL_MEMOIZER_EXPIRATION is set before either backend is constructed, so the benchmark avoids cached OSHI reads as intended.

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

49-70: LGTM.

The setup disables memoization before backend construction, and both benchmark methods consume equivalent JNA/FFM memory-query results.

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

44-50: Memoization setup is in the right place.

GlobalConfig.OSHI_UTIL_MEMOIZER_EXPIRATION is set before either HAL is created, so the benchmark avoids cached OSHI reads as intended.

Comment on lines +53 to +65
@Benchmark
public void jna(Blackhole bh) {
for (OSFileStore store : jnaStores) {
bh.consume(store.updateAttributes());
}
}

@Benchmark
public void ffm(Blackhole bh) {
for (OSFileStore store : ffmStores) {
bh.consume(store.updateAttributes());
}
}

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.

⚠️ Potential issue | 🟡 Minor

Clarify or normalize the benchmark unit.

These methods measure one JMH invocation across all discovered file stores, not per store. If JNA and FFM enumerate different counts—or CI hosts differ—the reported average time can be misread as per-store overhead. Consider renaming/reporting this as “all stores” or changing the benchmark to update one store per invocation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-benchmark/src/main/java/oshi/benchmark/FileStoreBenchmark.java` around
lines 53 - 65, The jna and ffm benchmarks currently iterate over all discovered
stores (jnaStores and ffmStores) so the measured time is for "all stores" rather
than per-store; either rename the benchmark methods to indicate "allStores"
(e.g., jnaAllStores / ffmAllStores) to clarify reporting, or change the
benchmark to operate on a single store per invocation by selecting one store
(use a `@Setup` to pick a fixed index or a `@Param` for store index or use
ThreadLocalRandom to pick an index) and update jna and ffm to call
updateAttributes() on only that one store (ensure jnaStores and ffmStores remain
available for selection).

Comment on lines +53 to +65
@Benchmark
public void jna(Blackhole bh) {
for (NetworkIF nif : jnaIfs) {
bh.consume(nif.updateAttributes());
}
}

@Benchmark
public void ffm(Blackhole bh) {
for (NetworkIF nif : ffmIfs) {
bh.consume(nif.updateAttributes());
}
}

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.

⚠️ Potential issue | 🟡 Minor

Clarify or normalize the benchmark unit.

These methods measure one JMH invocation across all discovered network interfaces, not per interface. If JNA and FFM enumerate different counts—or CI hosts differ—the reported average time can be misread as per-interface overhead. Consider renaming/reporting this as “all interfaces” or changing the benchmark to update one interface per invocation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java` around
lines 53 - 65, The benchmark methods jna and ffm currently measure one JMH
invocation across all discovered interfaces (iterating jnaIfs and ffmIfs), which
can mislead readers into thinking times are per-interface; either rename the
methods to clarify they measure "all interfaces" (e.g., jnaAllInterfaces,
ffmAllInterfaces) or change the benchmark to update exactly one interface per
invocation by selecting a single NetworkIF from jnaIfs/ffmIfs (use a stable
selector like ThreadLocal/AtomicInteger modulo the list size or
ThreadLocalRandom) and call updateAttributes() on that single element so results
reflect per-interface timing. Ensure you update the benchmark method names and
JMH annotations or the selection logic consistently for both jna and ffm.

Add CpuTicks, Memory, FileStore, and NetworkIF benchmarks comparing
JNA vs FFM implementations. All benchmarks disable memoization to
measure actual native call overhead.

Run benchmarks on JDK 25 at the end of CI on all platforms (linux,
macos, windows, PR) with abbreviated iterations (-wi 1 -i 3 -f 1).

Also fix stale oshi-core-java25 reference in run-benchmarks.sh and
suppress shade plugin's dependency-reduced-pom.xml generation.

@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.

♻️ Duplicate comments (1)
oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java (1)

53-65: ⚠️ Potential issue | 🟡 Minor

Benchmark unit is "all interfaces", not per interface — results can be misread when JNA vs FFM enumerate different counts.

Each @Benchmark invocation calls updateAttributes() once for every element in jnaIfs / ffmIfs. If the two implementations enumerate a different number of interfaces (e.g., inclusion of loopback/virtual adapters differs), the AverageTime numbers aren't an apples-to-apples per-interface comparison. A couple of options:

  • Rename to jnaAllInterfaces / ffmAllInterfaces and log the list sizes in @Setup so the reader can normalize.
  • Or, divide by size by switching to @OperationsPerInvocation(n) once the counts are known equal, or select a single stable interface per invocation.

Same observation applies to FileStoreBenchmark if it follows the same pattern.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java` around
lines 53 - 65, The benchmarks jna() and ffm() iterate over jnaIfs and ffmIfs
calling updateAttributes(), so their reported AverageTime is "all interfaces"
not per-interface and can mislead if the lists differ; fix by either (A)
renaming methods to jnaAllInterfaces()/ffmAllInterfaces() and record
jnaIfs.size()/ffmIfs.size() in the `@Setup` so results can be normalized, or (B)
ensure equal counts and annotate the benchmark with `@OperationsPerInvocation`(n)
using the common size (or pick one stable NetworkIF and benchmark
per-invocation), and apply the same change pattern to FileStoreBenchmark if it
uses the same multi-item iteration; update method names, `@Setup` logging, or add
`@OperationsPerInvocation` and selection logic accordingly.
🧹 Nitpick comments (1)
oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java (1)

44-51: Consider asserting non-empty lists in @Setup.

If a CI runner enumerates zero network interfaces (unlikely but possible in stripped containers), both benchmarks become no-ops and JMH will happily report sub-nanosecond times. A cheap guard in @Setup (e.g., throw if either list is empty) would surface that misconfiguration rather than produce meaningless results.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java` around
lines 44 - 51, The setup method may yield empty jnaIfs or ffmIfs making
benchmarks meaningless; update the setup() in NetworkIFBenchmark to validate
that jnaIfs and ffmIfs are non-empty (e.g., check jnaIfs.isEmpty() or
ffmIfs.isEmpty()) and throw an IllegalStateException or AssertionError with a
clear message (referencing jnaIfs and ffmIfs) when either list is empty so CI or
local runs fail fast instead of producing invalid sub-nanosecond results.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java`:
- Around line 53-65: The benchmarks jna() and ffm() iterate over jnaIfs and
ffmIfs calling updateAttributes(), so their reported AverageTime is "all
interfaces" not per-interface and can mislead if the lists differ; fix by either
(A) renaming methods to jnaAllInterfaces()/ffmAllInterfaces() and record
jnaIfs.size()/ffmIfs.size() in the `@Setup` so results can be normalized, or (B)
ensure equal counts and annotate the benchmark with `@OperationsPerInvocation`(n)
using the common size (or pick one stable NetworkIF and benchmark
per-invocation), and apply the same change pattern to FileStoreBenchmark if it
uses the same multi-item iteration; update method names, `@Setup` logging, or add
`@OperationsPerInvocation` and selection logic accordingly.

---

Nitpick comments:
In `@oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java`:
- Around line 44-51: The setup method may yield empty jnaIfs or ffmIfs making
benchmarks meaningless; update the setup() in NetworkIFBenchmark to validate
that jnaIfs and ffmIfs are non-empty (e.g., check jnaIfs.isEmpty() or
ffmIfs.isEmpty()) and throw an IllegalStateException or AssertionError with a
clear message (referencing jnaIfs and ffmIfs) when either list is empty so CI or
local runs fail fast instead of producing invalid sub-nanosecond results.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 21006909-e701-41d1-8af6-3b5c3f8ed067

📥 Commits

Reviewing files that changed from the base of the PR and between f4968b3 and 4970f29.

📒 Files selected for processing (10)
  • .github/workflows/linux.yaml
  • .github/workflows/macos.yaml
  • .github/workflows/pr.yaml
  • .github/workflows/windows.yaml
  • oshi-benchmark/pom.xml
  • oshi-benchmark/scripts/run-benchmarks.sh
  • oshi-benchmark/src/main/java/oshi/benchmark/CpuTicksBenchmark.java
  • oshi-benchmark/src/main/java/oshi/benchmark/FileStoreBenchmark.java
  • oshi-benchmark/src/main/java/oshi/benchmark/MemoryBenchmark.java
  • oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java
✅ Files skipped from review due to trivial changes (3)
  • oshi-benchmark/pom.xml
  • oshi-benchmark/scripts/run-benchmarks.sh
  • oshi-benchmark/src/main/java/oshi/benchmark/FileStoreBenchmark.java
🚧 Files skipped from review as they are similar to previous changes (4)
  • .github/workflows/windows.yaml
  • oshi-benchmark/src/main/java/oshi/benchmark/CpuTicksBenchmark.java
  • oshi-benchmark/src/main/java/oshi/benchmark/MemoryBenchmark.java
  • .github/workflows/pr.yaml
📜 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). (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:43.529Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
📚 Learning: 2026-04-18T03:18:03.725Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).

Applied to files:

  • oshi-benchmark/src/main/java/oshi/benchmark/NetworkIFBenchmark.java
🔇 Additional comments (2)
.github/workflows/linux.yaml (1)

78-82: LGTM.

The -am flag addresses the earlier concern about building in-repo snapshot dependencies, and gating on matrix.java == '25' correctly scopes the benchmark to the JDK that supports FFM's --enable-native-access.

.github/workflows/macos.yaml (1)

54-58: LGTM.

Mirrors the Linux workflow and picks up -am from the prior review round.

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