Comments (7)
@Doprez
I've resolved the issue you reported!
50ea674 - used option keepInterResults
to save memory
from dotrecast.
Switching to the ArrayPool instead of having the static reference seems to fix the test issue and performs as well in allocations as far as I can tell.
The next thing to look into is the RcSpan allocations, I cant seem to create the same fix so I will need something different for that issue.
from dotrecast.
@Doprez Hello!
I wanted to inform you that we received a PR regarding this matter. One has been merged, and the other one is currently under review.I've been quite busy with work lately and haven't been able to pay much attention, but I'll try to make the necessary adjustments as soon as possible.
Could you please send me the test obj model that I can review?
from dotrecast.
from dotrecast.
Oh wow, after some quick testing with my previous project the difference is huge!
System.Single[]
Objects : n/a
Bytes : 534944
20.6% DividePoly • 107.7 KB / 107.7 KB • DotRecast.Recast.RcRasterizations.DividePoly(Single[], Int32, Int32, Int32, Int32, Int32, Int32, Single, Int32)
20.6% RasterizeTriangles • 107.7 KB / - • DotRecast.Recast.RcRasterizations.RasterizeTriangles(RcContext, Single[], Int32[], Int32[], Int32, RcHeightfield, Int32)
20.6% BuildSolidHeightfield • 107.7 KB / - • DotRecast.Recast.RcVoxelizations.BuildSolidHeightfield(RcContext, IInputGeomProvider, RcBuilderConfig)
20.6% <BuildMultiThreadAsync>b__0 • 107.7 KB / - • DotRecast.Recast.RcBuilder+<>c__DisplayClass6_1.<BuildMultiThreadAsync>b__0()
20.6% RunFromThreadPoolDispatchLoop • 107.7 KB / - • System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread, ExecutionContext, ContextCallback, Object)
20.6% ExecuteWithThreadLocal • 107.7 KB / - • System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task, Thread)
20.6% Dispatch • 107.7 KB / - • System.Threading.ThreadPoolWorkQueue.Dispatch()
20.6% WorkerThreadStart • 107.7 KB / - • System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()
► 20.6% [AllThreadsRoot] • 107.7 KB / - • [AllThreadsRoot]
#stacktrace
I dont even see AddSpan
in the allocations list anymore but the total allocationsare 147MB compared to the almost 900MB before.
I think this is good to close for the initial reported issue, Ill open a new one if something comes up. Thank you!
from dotrecast.
So I think I found at least one solution for the Singles being allocated?
The old stacktrace with 1.5GB allocations:
The new stacktrace with 266KB allocations:
The change made here was to move the float array to be a static reference instead of making a new float array on each method call.
from:
/// Divides a convex polygon of max 12 vertices into two convex polygons
/// across a separating axis.
///
/// @param[in] inVerts The input polygon vertices
/// @param[in] inVertsCount The number of input polygon vertices
/// @param[out] outVerts1 Resulting polygon 1's vertices
/// @param[out] outVerts1Count The number of resulting polygon 1 vertices
/// @param[out] outVerts2 Resulting polygon 2's vertices
/// @param[out] outVerts2Count The number of resulting polygon 2 vertices
/// @param[in] axisOffset THe offset along the specified axis
/// @param[in] axis The separating axis
private static void DividePoly(float[] inVerts, int inVertsOffset, int inVertsCount,
int outVerts1, out int outVerts1Count,
int outVerts2, out int outVerts2Count,
float axisOffset, int axis)
{
// How far positive or negative away from the separating axis is each vertex.
float[] inVertAxisDelta = new float[12];
for (int inVert = 0; inVert < inVertsCount; ++inVert)
{
inVertAxisDelta[inVert] = axisOffset - inVerts[inVertsOffset + inVert * 3 + axis];
}
....
to:
private static readonly float[] _inVertAxisDelta = new float[12];
/// Divides a convex polygon of max 12 vertices into two convex polygons
/// across a separating axis.
///
/// @param[in] inVerts The input polygon vertices
/// @param[in] inVertsCount The number of input polygon vertices
/// @param[out] outVerts1 Resulting polygon 1's vertices
/// @param[out] outVerts1Count The number of resulting polygon 1 vertices
/// @param[out] outVerts2 Resulting polygon 2's vertices
/// @param[out] outVerts2Count The number of resulting polygon 2 vertices
/// @param[in] axisOffset THe offset along the specified axis
/// @param[in] axis The separating axis
private static void DividePoly(float[] inVerts, int inVertsOffset, int inVertsCount,
int outVerts1, out int outVerts1Count,
int outVerts2, out int outVerts2Count,
float axisOffset, int axis)
{
// How far positive or negative away from the separating axis is each vertex.
float[] inVertAxisDelta = _inVertAxisDelta;
for (int inVert = 0; inVert < inVertsCount; ++inVert)
{
inVertAxisDelta[inVert] = axisOffset - inVerts[inVertsOffset + inVert * 3 + axis];
}
....
I'm not sure if this is a proper solution but the results seem to be a bit improved at least. The only issue I found is the performance test fails with this change so a bit more investigation is needed here.
from dotrecast.
@Doprez Hello!
I wanted to inform you that we received a PR regarding this matter. One has been merged, and the other one is currently under review.I've been quite busy with work lately and haven't been able to pay much attention, but I'll try to make the necessary adjustments as soon as possible.
Could you please send me the test obj model that I can review?
I added it to a repo here with the cube https://github.com/Doprez/RandomFileShare/blob/main/500x500-cube.obj
Its the default cube from blender scaled high. I also tried with your large terrain example and the same issue is there but with less allocations. I am wondering if more verts helps in some odd way but I havent been able to properly test that thought.
If I have some time after work today I will try to make a PR for the Single/float allocations. I was happy to see someone took care of the RcSpan because that one was stumping me a bit lol.
edit: nevermind about my PR that person beat me to it lol
from dotrecast.
Related Issues (20)
- Gallery: Post your screenshots / code here HOT 8
- Unity sample. HOT 1
- Performance with System.Numerics and Multithreading HOT 20
- Crowd Control ignores Temp Obstacles? HOT 1
- [Help] How can I get the indices of the generated navmesh? HOT 2
- [Help] Nav mesh being generated upside down HOT 4
- Increase UI Elements Sizing HOT 2
- Updates to Demo HOT 9
- Bug in Demo with Convex Volume Creation HOT 4
- SOH allocation issues HOT 49
- Invert X axis HOT 2
- Importing data HOT 6
- Memcpy and heap allocations in DtCrowdTelemetry.Stop() HOT 1
- Question: Mesh DetaiIs are null after mesh generation HOT 1
- System.ArgumentException:“'0' cannot be greater than -1.” HOT 11
- Problems with removed vertices at tile borders HOT 1
- Problem with contour simplification. HOT 1
- DotRecast creating a lot of RcSpan objects for a relatively small scene. HOT 6
- "Create Temp Obstacles" doesn't work HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dotrecast.