Coder Social home page Coder Social logo

Comments (20)

ikpil avatar ikpil commented on September 28, 2024 1

I've added a new branch with a version that uses SIMD. While it needs testing on various architectures, it has already increased performance by over 50% on my current laptop. I'll continue with more R&D, and once I'm confident it's safe, I'll plan to merge it into the main branch.

@GabrielMotaAlexandre

from dotrecast.

galvesribeiro avatar galvesribeiro commented on September 28, 2024 1

ConcurrentQueue does a hard lock internally. So the Enqueue() call is essentially blocking the thread.

We use DotRecast in a server which is based on Microsoft Orleans. Locks in that context are extremely harmful. So I guess in our case the SemaphoreSlim would be better.

from dotrecast.

ikpil avatar ikpil commented on September 28, 2024

Compatibility Issues

System.Numerics.Vector3 leverages SIMD (Single Instruction, Multiple Data) instructions for optimized vector operations, which can be very fast for certain operations. However, SIMD operations can significantly vary in performance depending on the data structures and types of operations involved.

For example, using Vector3 may actually be slower for performing operations on small-sized vectors or simple scalar operations. Furthermore, SIMD extensions may not be supported on all hardware, making it unavailable in certain environments.

from dotrecast.

GabrielMotaAlexandre avatar GabrielMotaAlexandre commented on September 28, 2024

I couldn't find topics related to downsides, I could imagine very few case Vector3 would be slower but overall I thought it would be worth it.

from dotrecast.

ikpil avatar ikpil commented on September 28, 2024

Could you please provide your environment?
Could you provide me with the DLL that you've built?
Would you like to try running the build artifacts on a different CPU environment?

from dotrecast.

GabrielMotaAlexandre avatar GabrielMotaAlexandre commented on September 28, 2024

I edited my comment in case it was misinterpreted.

from dotrecast.

ikpil avatar ikpil commented on September 28, 2024

See info

from dotrecast.

GabrielMotaAlexandre avatar GabrielMotaAlexandre commented on September 28, 2024

Thanks, grat news.

from dotrecast.

galvesribeiro avatar galvesribeiro commented on September 28, 2024

Hello folks!

Any updates on the SIMD support?

We are using it on the server side for an unannounced MMO and results are good with this port. However, we would like to indeed leverage SIMD on this.

On that subject - are DtCrowdAgent.RequestMoveTarget()/.AddAgent()/.RemoveAgent() thread-safe?

Thanks!

from dotrecast.

ikpil avatar ikpil commented on September 28, 2024
  1. SIMD will be supported. However, we are currently working on fixing the SOH issue first.

  2. By default, RecastNavigation is not thread-safe. The ported DotRecast is also not thread-safe. Therefore, when using it, use isolation or a Query pool to use multiple instances.

@galvesribeiro

from dotrecast.

galvesribeiro avatar galvesribeiro commented on September 28, 2024

Thanks for the reply @ikpil

We only use DtCrowd and NavQuery/NavMesh. In that case, I guess we should have a SemaphoreSlim(1,1) being used whenever we need to call Add/Remove agent and Update.

Is that enough to protect the Write operations but Read from any thread without "lock"?

Again, thanks for the great work on this port!

from dotrecast.

ikpil avatar ikpil commented on September 28, 2024

I haven't tested it, but just take a look at the feeling.
@galvesribeiro

        public class DtCrowdManager
        {
            private DtCrowd _crowd;
            private ConcurrentQueue<Action> _requests;

            public DtCrowdManager(DtCrowd crowd)
            {
                _crowd = crowd;
                _requests = new ConcurrentQueue<Action>();
            }

            // DtCrowdAgent -  should only read.
            // AddAsync - thread-safe
            public Task<DtCrowdAgent> AddAsync(RcVec3f pos, DtCrowdAgentParams option)
            {
                var tcs = new TaskCompletionSource<DtCrowdAgent>(TaskCreationOptions.RunContinuationsAsynchronously);
                _requests.Enqueue(() =>
                {
                    var ag = _crowd.AddAgent(RcVec3f.Zero, null); // ..
                    tcs.SetResult(ag);
                });

                return tcs.Task;
            }

            // RemoveAsync - thread-safe
            public Task<bool> RemoveAsync(DtCrowdAgent ag)
            {
                var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
                _requests.Enqueue(() =>
                {
                    _crowd.RemoveAgent(ag);
                    tcs.SetResult(true); // ...
                });

                return tcs.Task;

            }

            // It should be called only from one thread.
            public void Update(float dt)
            {
                while (_requests.TryDequeue(out var action))
                {
                    action.Invoke();
                }
                
                _crowd.Update(dt, null);
            }
        }

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.