java-native-access / java-native-access/jna
Performance Issue with Union
Nobody has claimed this yet.
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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