java-native-access / java-native-access/jna

Performance Issue with Union

Open
#294 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug? needs work
Dominant language
Java
Stars
8.9k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

I have a Union inside a Struct (with other primitive fields). The struct I implements Structure.ByReference and initialize it with a Pointer.

Inside the Union there is a few Structure with different size.

It works correctly when I do a read() on the outer Structure after setting the Union to the correct type. However the performance is 2-3x slower than when I process the Union separately.

By separately I mean I need to break the Union into normal Structure and dispatch them based on input information and init with a Pointer and an offset. The faster method however is not good since the offset in 32-bit machine and 64-bit machine is different.

So I guess the problem is the offset calculation internally of JNA. I am not sure if this is a known problem or I was doing it the wrong way. I tested with JNA 4.0.0 from the download link.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with JNA 4.0.0 using an outer Structure.ByReference containing a Union of differently sized Structures, then compare read() performance with separate Structures initialized from a Pointer and offset. Test on both 32-bit and 64-bit systems; done means identifying whether internal offset calculation causes the slowdown or documenting that the behavior is expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.