• Hi Guest!

    We are extremely excited to announce the release of our first Beta1.1 and the first release of our Public AddonKit!
    To participate in the Beta, a subscription to the Entertainer or Creator Tier is required. For access to the Public AddonKit you must be a Creator tier member. Once subscribed, download instructions can be found here.

    Click here for information and guides regarding the VaM2 beta. Join our Discord server for more announcements and community discussion about VaM2.
  • Hi Guest!

    VaM2 Resource Categories have now been added to the Hub! For information on posting VaM2 resources and details about VaM2 related changes to our Community Forums, please see our official announcement here.
Heap Monitor

Plugins + Scripts Heap Monitor

Download [<1 MB]

Skynet

Invaluable member
Featured Contributor
Joined
Jan 28, 2023
Messages
649
Reactions
4,132
Skynet submitted a new resource:

Heap Monitor - Developer Tool to monitor Memory leaks making memory optimizations for plugins easier

-- Content:
- HeapMonitor script file.

-- Description:
- Developer tool that measures currently used Heap Memory with Heap growth rate, makes it easy to identify memory leak sources when debugging your plugins.
- Keybind Shortcut: "Ctrl + H" to toggle the Heap Info Overlay.
- Menu to choose which corner of the display the Overlay aligns with.

-- Preview of UI & Overlay:
View attachment 565464

Read more about this resource...
 
This is a very interesting and helpful tool! Are there any rules of thumb on how much memory growth rate is still "sustainable" or what is considered "leaky"? Is any continuous memory increase a problem?
 
This is a very interesting and helpful tool! Are there any rules of thumb on how much memory growth rate is still "sustainable" or what is considered "leaky"? Is any continuous memory increase a problem?
In an ideal scenario you'd want the Rate to be as close to 0MB/s as possible, excluding the occasional spikes. but of course that's extremely hard so anything below 0.2MB/s is good, i myself was struggling with memory leaks in Orifice dynamics until recently when i made this which helped me figure out the sources.

The main tip i can give is to make conditional wrappers around methods in question that run in update loops (Update, FixedUpdate & LateUpdate) and add the condition bools as a UI toggles to be able to see which methods cause the leak. with AI you can integrate this fairly quickly in any plugin, there will be some examples of this in the upcoming Orifice Dynamics v24 update.

The problem that can happen from memory leak is frequent GC spikes (game freezes) and indefinite growth of RAM usage which can lead to crashes sometimes
 
The main tip i can give is to make conditional wrappers around methods in question that run in update loops (Update, FixedUpdate & LateUpdate) and add the condition bools as a UI toggles to be able to see which methods cause the leak. with
Thanks, thats an interesting tipp! I will try this. I suppose the toggles do not even need to be in the UI but can be activated/deactivated in the code only.
 
Thanks, thats an interesting tipp! I will try this. I suppose the toggles do not even need to be in the UI but can be activated/deactivated in the code only.
np, and yeah either way works. do what's more convenient for you, another thing i forgot to tell is that the main sources of heap growth is the usage of collections like array, list, hashset... etc from what i've learned
 
np, and yeah either way works. do what's more convenient for you, another thing i forgot to tell is that the main sources of heap growth is the usage of collections like array, list, hashset... etc from what i've learned
It's really cool to use this tool to optimise memory usage! I am currently optimising my Foreskin & Erection suite which was at around 0.3 MB/sec initially and can be reduced to one third rougly. Most relevant point in my case is replacing GetStorableIDs() with GetStorablebyID() or at least only trigger this when needed and not periodically.

I also found that all sim hair on males only (!?) lead to quite considerable memory leaks (0.8 MB/sec) which seems strange to me, but it is reproducible. Looks like a bug in VaM maybe?
 
It's really cool to use this tool to optimise memory usage! I am currently optimising my Foreskin & Erection suite which was at around 0.3 MB/sec initially and can be reduced to one third rougly. Most relevant point in my case is replacing GetStorableIDs() with GetStorablebyID() or at least only trigger this when needed and not periodically.

I also found that all sim hair on males only (!?) lead to quite considerable memory leaks (0.8 MB/sec) which seems strange to me, but it is reproducible. Looks like a bug in VaM maybe?
yeah doing stuff every frame is where the problem stems from, depending on what are trying to access you can use the OnAtomAdded & OnAtomRemoved along with some other useful events to act as triggers for methods in question, there's plenty more in the SuperController class that you can make use of.

as for the hair, i have no idea tbh.
 
yeah doing stuff every frame is where the problem stems from, depending on what are trying to access you can use the OnAtomAdded & OnAtomRemoved along with some other useful events to act as triggers for methods in question, there's plenty more in the SuperController class that you can make use of.

as for the hair, i have no idea tbh.
I pay attention to only do morph changes or collider stuff each frame or even physics update, and all the rest is carefully reduced to every 15, 60 or even 100 frames and evenly distributed over time with a timer function. But the GetStorableIDs are expensive even if done at reasonably low frequency. I have so far not found any good combination of triggers/methods to reliably detect the relevant changes, which involve plugin add/remove, appearance changes (I sometimes use a morphs sum comparison), or even detecting on which sub-UI the user is (which seems impossible, the last seen UI keeps running in the background if you close the persons plugin panel). So I battle to find the most efficient triggers for each case, to reduce CPU time and memory usage.
 
I pay attention to only do morph changes or collider stuff each frame or even physics update, and all the rest is carefully reduced to every 15, 60 or even 100 frames and evenly distributed over time with a timer function. But the GetStorableIDs are expensive even if done at reasonably low frequency. I have so far not found any good combination of triggers/methods to reliably detect the relevant changes, which involve plugin add/remove, appearance changes (I sometimes use a morphs sum comparison), or even detecting on which sub-UI the user is (which seems impossible, the last seen UI keeps running in the background if you close the persons plugin panel). So I battle to find the most efficient triggers for each case, to reduce CPU time and memory usage.
yeah couldn't agree more, I hope Meshed provides us with an extended set of event triggers in Vam 2 that we can use for these types of situations. many times when i find a flag/ bool that can be used as a trigger it often is protected an can't be accessed
 
Back
Top Bottom