Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variant memory allocations #184

Closed
ghost opened this issue Aug 18, 2022 · 3 comments
Closed

Variant memory allocations #184

ghost opened this issue Aug 18, 2022 · 3 comments

Comments

@ghost
Copy link

ghost commented Aug 18, 2022

After resolving #182, instances of Variant now dominate memory profiling, as shown in the screenshot:

Variant

The GC profiling shows:

GC

Is there anything that can be done to reduce the number of Variant instances created? There appears to be a 1:1 relationship with a Message instance.

@hypfvieh
Copy link
Owner

That will not be easy to fix (if it is fixable at all).
A Variants array is used in the header of each message (DBus Spec) and this header will be read first when a message is transformed to a Java object.

So the same code as for reading anything else on the message is used to get that header information.
This is good in terms of re-using the code, but bad because for the header map in the message only the contents of the variant is stored. Therefore for each messages an arbitrary amount of variants is created, the containing value is stored and the variant itself will be ignored (therefore are eligible for garbage collection).

I'll take a closer look to that, maybe I can refactor some points to get rid of the overhead of creating variant objects.

@hypfvieh
Copy link
Owner

Alright, after hours of investigating, optimizing and refactoring I added a new branch with my changes.

The change will use a new method to read the header for each message which will not create the Variant objects.
Instead it will read the data object of the Variant directly and return this in the Object[] instead of the Variant.
Before the change, Object[] read from message contained Byte + Variant, now it contains Byte + Object.
This allows storing the Object directly in the header map (which is Map<Byte, Object>) of the message without unwrapping the Variant first.

@ghost
Copy link
Author

ghost commented Aug 19, 2022

Thank you! The Variant instances are now gone in the small demo program I wrote:

dbus-no-variant

In our main application, the Message objects promote to Gen 2, which decreases stress on the GC. Decreasing the GC stress reduces the probability of stop-the-world pauses. We have tight timing constraints where stop-the-world events can cause buffer overruns, resulting in dropped data.

Preliminary application tests show significant improvements: there are far fewer stop-the-world events now. We're basically back to pre-D-Bus integration performance. Much appreciated.

@ghost ghost closed this as completed Aug 19, 2022
This issue was closed.
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

No branches or pull requests

1 participant