Skip to content

Add FFM vs. JNA performance comparison to Performance.md - #3196

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:doc/ffm-vs-jna-performance
Apr 26, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:doc/ffm-vs-jna-performance

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 25, 2026 •

Copy link
Copy Markdown
Member

Adds a new section to Performance.md documenting FFM vs. JNA benchmark results across macOS, Windows, and Linux.

Summary by CodeRabbit

  • Documentation
    • Added a new performance comparison detailing differences between JNA- and FFM-based backends, JDK requirements, and supported platforms.
    • Published JMH benchmark results for macOS, Windows, and Linux with platform-specific notes on observed differences.
    • Added step-by-step guidance and example commands for running local performance benchmarks and viewing benchmark options.

@coderabbitai

coderabbitai Bot commented Apr 25, 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: dc2bf47b-f71c-4386-be24-fff68e1bed66

📥 Commits

Reviewing files that changed from the base of the PR and between d797c62 and d097869.

📒 Files selected for processing (1)
  • src/site/markdown/Performance.md
✅ Files skipped from review due to trivial changes (1)
  • src/site/markdown/Performance.md

📝 Walkthrough

Walkthrough

Adds an "FFM vs. JNA" section to the Performance guide documenting OSHI's two native backends, JMH benchmark timings for macOS/Windows/Linux, and instructions/examples for running the oshi-benchmark locally (JDK 25+ for FFM).

Changes

Cohort / File(s) Summary
Performance Documentation
src/site/markdown/Performance.md
Added "FFM vs. JNA" section describing the two native backends (oshi-core JNA for JDK 8+, oshi-core-ffm FFM for JDK 25+), included OS- and benchmark-specific JMH timing tables (macOS, Windows, Linux), platform notes, and local JMH run instructions and examples (including -h).

Estimated Code Review Effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Poem

🌟 Two bridges to native lands arise,
JNA steadies, FFM flies,
Benchmarks whisper platform tales,
Commands to run and view the trails,
Cheers to curious minds who try!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and directly describes the main change: adding a FFM vs. JNA performance comparison section to Performance.md.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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

🧹 Nitpick comments (1)
src/site/markdown/Performance.md (1)

49-59: Clear and actionable benchmark instructions.

The Maven and JMH commands are correct and the JAR name matches the build configuration. The parameters align with the benchmark setup described earlier, and the guidance to increase iteration counts for stability is practical advice.

Optional: Consider mentioning how to list available benchmarks.

For users who want to run specific benchmarks rather than the full suite, you could optionally add a brief note about listing available benchmarks:

📋 Optional addition
 Increase `-wi` (warmup iterations), `-i` (measurement iterations), and `-f` (forks) for more stable results.
+
+To list available benchmarks or run specific ones, use `-l` to list or provide a pattern:
+
+```sh
+java -jar oshi-benchmark/target/benchmarks.jar -l
+java -jar oshi-benchmark/target/benchmarks.jar ".*CpuTicks.*" -wi 1 -i 3 -f 1
+```
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/site/markdown/Performance.md` around lines 49 - 59, Update the "Running
benchmarks locally" section in Performance.md to include an optional collapsible
note that shows how to list available JMH benchmarks from the built
bench­marks.jar and how to run a single benchmark by supplying a regex filter
(for example matching "CpuTicks"); add short, copy-pastable example commands for
listing (-l) and running a specific benchmark with a regex and the same
-wi/-i/-f options so users can target individual tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/site/markdown/Performance.md`:
- Around line 49-59: Update the "Running benchmarks locally" section in
Performance.md to include an optional collapsible note that shows how to list
available JMH benchmarks from the built bench­marks.jar and how to run a single
benchmark by supplying a regex filter (for example matching "CpuTicks"); add
short, copy-pastable example commands for listing (-l) and running a specific
benchmark with a regex and the same -wi/-i/-f options so users can target
individual tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a926bf23-38e7-4cd7-8603-5e8019b48b1f

📥 Commits

Reviewing files that changed from the base of the PR and between 48fbcf2 and d797c62.

📒 Files selected for processing (1)
  • src/site/markdown/Performance.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). (1)
  • GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
🧠 Learnings (8)
📓 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:06.205Z
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: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:35.860Z
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.
📚 Learning: 2026-04-18T03:18:06.205Z
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:06.205Z
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:

  • src/site/markdown/Performance.md
📚 Learning: 2026-04-17T23:43:35.860Z
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:35.860Z
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:

  • src/site/markdown/Performance.md
📚 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:

  • src/site/markdown/Performance.md
📚 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:

  • src/site/markdown/Performance.md
📚 Learning: 2026-04-19T01:28:47.155Z
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:47.155Z
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:

  • src/site/markdown/Performance.md
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

  • src/site/markdown/Performance.md
📚 Learning: 2026-04-12T19:34:59.050Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:59.050Z
Learning: The counterintuitive naming of `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` in OSHI (where a higher value means MORE performance and LESS efficiency, so P-cores get higher values than E-cores) is intentionally inherited from Microsoft's `PROCESSOR_RELATIONSHIP.EfficiencyClass` Win32 API: "A core with a higher value for the efficiency class has intrinsically greater performance and less efficiency." OSHI follows this same convention for cross-platform consistency. Do not flag P-cores being assigned higher efficiency values as a bug.

Applied to files:

  • src/site/markdown/Performance.md
🔇 Additional comments (4)
src/site/markdown/Performance.md (4)

4-10: Excellent introduction to the two implementations!

The technical descriptions are accurate and the platform/JDK version requirements align perfectly with the codebase configuration. The explanation clearly distinguishes the overhead characteristics of reflection-based marshalling versus compiler-optimized stubs.


11-24: Clear presentation of macOS benchmarks.

The table is well-formatted and the explanation correctly identifies why FFM shows the largest advantage on macOS—the heavy use of native syscalls like sysctl and proc_pidinfo compounds FFM's per-call overhead savings. The benchmark parameters stated here match the example command provided later in the document.


25-36: Great transparency about the Windows Processes regression.

The documentation honestly highlights where JNA currently outperforms FFM and provides a clear technical explanation (registry-based HKEY_PERFORMANCE_DATA queries vs. per-process native calls) along with traceability to the tracking issue. This transparency helps users make informed decisions.


37-48: Accurate explanation of Linux's minimal FFM advantage.

The explanation correctly identifies that Linux's /proc and /sys pseudo-filesystems minimize the benefit of FFM's lower native call overhead since most data comes from file reads. The FileStore exception is well-documented, showing where direct statvfs calls still provide measurable benefit.

@dbwiddis
dbwiddis force-pushed the doc/ffm-vs-jna-performance branch from d797c62 to d097869 Compare April 25, 2026 23:59
@dbwiddis
dbwiddis merged commit ef3e4bc into oshi:master Apr 26, 2026
2 checks passed
@dbwiddis
dbwiddis deleted the doc/ffm-vs-jna-performance branch April 26, 2026 00:12
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