Git Product home page Git Product logo

Comments (7)

ikpil avatar ikpil commented on August 19, 2024 2

@Doprez
I've resolved the issue you reported!

50ea674 - used option keepInterResults to save memory

from dotrecast.

Doprez avatar Doprez commented on August 19, 2024 1

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.

ikpil avatar ikpil commented on August 19, 2024 1

@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.

ikpil avatar ikpil commented on August 19, 2024 1

#62
#63

from dotrecast.

Doprez avatar Doprez commented on August 19, 2024 1

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.

Doprez avatar Doprez commented on August 19, 2024

So I think I found at least one solution for the Singles being allocated?

The old stacktrace with 1.5GB allocations:
image

The new stacktrace with 266KB allocations:
image

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.
image

from dotrecast.

Doprez avatar Doprez commented on August 19, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.