-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
SOH allocation issues #41
Comments
I'll check and mention you!! |
Using stack memory introduces some potential risks that need careful consideration. before // Build sampling pattern aligned to desired velocity.
float[] pat = new float[(DT_MAX_PATTERN_DIVS * DT_MAX_PATTERN_RINGS + 1) * 2]; after // Build sampling pattern aligned to desired velocity.
int patSize = (DT_MAX_PATTERN_DIVS * DT_MAX_PATTERN_RINGS + 1) * 2;
RcStackArray512<float> pat = RcStackArray512<float>.Empty;
ThrowHelper.ThrowExceptionIfIndexOutOfRange(patSize - 1, pat.Length); |
Hey, thanks for taking the time to look at the issue. The solution is a bit above my league so I can't really say anything. But if you wish to release a preview version I can see if the SOH warnings are gone |
I added RcRentedArray, which internally utilizes the functionality of ArrayPool. If everything seems fine with its features and usage, I will release it and mention you. Thank you for reporting the issue. [Test]
public void Test()
{
var rand = new RcRand();
for (int loop = 0; loop < 1024; ++loop)
{
int length = (int)(rand.Next() * 2048);
var values = RandomValues(length);
using var array = RcRentedArray.RentDisposableArray<float>(length);
for (int i = 0; i < array.Length; ++i)
{
array[i] = values[i];
}
for (int i = 0; i < array.Length; ++i)
{
Assert.That(array[i], Is.EqualTo(values[i]));
}
Assert.That(array[^1], Is.EqualTo(values[^1]));
Assert.Throws<IndexOutOfRangeException>(() => array[-1] = 0);
Assert.Throws<IndexOutOfRangeException>(() => array[array.Length + 1] = 0);
Assert.Throws<IndexOutOfRangeException>(() => _ = array[-1]);
Assert.Throws<IndexOutOfRangeException>(() => _ = array[array.Length + 1]);
}
} |
next !! |
There are some caveats to consider for allocating on stack. The stack is limited and size may vary on different platforms. The best case is to use it when you know size beforehand and can use constant. |
Here's benchmarking result for .NET 8.0 Native AOT
For some reason results on IL2CPP for |
Here's all allocations I've detected on each frame:
|
wow! thank you! |
Tried to merge pr/fix-small-object-heap-issue into master in my fork. Here are results. Before and after: |
@wrenge |
#41 (comment) array benchmark benchmark array test step2 test ss
fix: SOH issue step2 (#41) #41 fix: SOH issue step3 (#41) - #41 fix : SOH issue (#41) - #41 (comment) fix: SOH issue (#41) - #41 (comment) fix: SOH issue(#41) #41 (comment) array benchmark benchmark array test step2 test ss
fix: SOH issue step2 (#41) #41 fix: SOH issue step3 (#41) - #41 fix : SOH issue (#41) - #41 (comment) fix: SOH issue (#41) - #41 (comment) fix: SOH issue(#41) #41 (comment) array benchmark benchmark array test step2 test ss
fix: SOH issue step2 (#41) #41 fix: SOH issue step3 (#41) - #41 fix : SOH issue (#41) - #41 (comment) fix: SOH issue (#41) - #41 (comment) fix: SOH issue(#41) #41 (comment) array benchmark benchmark array test step2 test ss
fix: SOH issue step2 (#41) #41 fix: SOH issue step3 (#41) - #41 fix : SOH issue (#41) - #41 (comment) fix: SOH issue (#41) - #41 (comment) fix: SOH issue(#41) #41 (comment) array benchmark benchmark array test step2 test ss remove unused using dd
fix: SOH issue step2 (#41) #41 fix: SOH issue step3 (#41) - #41 fix : SOH issue (#41) - #41 (comment) fix: SOH issue (#41) - #41 (comment) fix: SOH issue(#41) #41 (comment) array benchmark benchmark array test step2 test ss remove unused using dd
fix: SOH issue step2 (#41) #41 fix: SOH issue step3 (#41) - #41 fix : SOH issue (#41) - #41 (comment) fix: SOH issue (#41) - #41 (comment) fix: SOH issue(#41) #41 (comment) array benchmark benchmark array test step2 test ss remove unused using dd
It was released on 2024.2.1. |
Rider keeps telling me that Small Object Heap allocation is high for the DtCrowd.Update method.
This is my usage
Where the Update method is called every 0.3...
On the pictures above the compiler is complaining about 200mb-ish, but I've seen it complaining about almost 800mb. Do you have any idea of what could it be?
The text was updated successfully, but these errors were encountered: