Code Monkey home page Code Monkey logo

Comments (7)

AndresTraks avatar AndresTraks commented on September 2, 2024

Good point. I'll consider the options.

from bulletsharp.

Zolniu avatar Zolniu commented on September 2, 2024

Wow, didn't expect such quick response! :) Currently I'm working on cache implementation in my client code. The only problem I have is to detect when new manifolds are added internally by Dispatcher. Once I have it figured out I'll post my solution - may be it'll help you.

Keep up the good work!

from bulletsharp.

AndresTraks avatar AndresTraks commented on September 2, 2024

Yeah, manifolds are hard to track since there are so many generated and handling them is performance-critical. Detecting when new manifolds are created is hard and it's also hard to detect when they are removed, which is again important for keeping garbage down.

I'm not sure if making PersistentManifold a struct helps, because they will be boxed into objects (e.g. when returned from GetManifoldByIndexInternal), so they'll still need to be garbage-collected.

This hasn't been a big priority so far, so I haven't thought about it very much. If you can figure it out, then that would be great. Thanks!

from bulletsharp.

AndresTraks avatar AndresTraks commented on September 2, 2024

Here's a patch that turns PersistentManifold into a value struct. Can you test it?
http://pastebin.com/5d72sLqS

The public PersistentManifold constructors are removed, but this is OK, because manifolds should only be created in Dispatcher::GetNewManifold anyway.
Also, since structs can't be inherited, PersistentManifold no longer inherits from TypedObject, but that probably isn't strictly necessary for anything.

After 7 years of .NET development, the GC is still confusing as hell :). But if I had to guess, there's less garbage generated with this patch since without the finalizer, the manifolds can be collected in GC generation 0 (if the PersistenManifolds should get boxed into objects).

from bulletsharp.

Zolniu avatar Zolniu commented on September 2, 2024

Ok, I'll test it once I have some time for it. I have forked your repository so you can push your fix in to it:

https://github.com/Zolniu/BulletSharp

In the meantime I've found quite good workaround for this problem. I use gContactProcessedCallback callback to store information about collisions and then I can work with them in my code. It produces a lot less garbage - I can have custom logic for over 800 colliding objects and I'm getting one garbage collection every few minuts. I had to modyfi PersistentManifold::onContactProcessed method to only fire if processed CollisionObject has CustomMaterialCallback flag. You can check it here:

https://github.com/Zolniu/BulletSharp/blob/master/src/PersistentManifold.cpp

About GC, it can be tricky indeed. Not only boxing can lead to "hidden" allocations, foreach over IEnumbrable also allocates memory, but only if used via IEnumerable interface. For example List provides explicit GetEnumerator() method which returns enumerator structure so foreach over List does't generate garbage, but if you change your reference to be IList (interface) it will generate garbage since foreach will use GetEnumerator() via IEnumerable interface inherited by IList interface.

from bulletsharp.

Zolniu avatar Zolniu commented on September 2, 2024

I've made some test in my with my current setup and it is quite obvious that after changing Persistent Manifold to struct you can iterate through all the manifolds without such massive amounts of memory allocations as before. I think we can close this issue.

BTW. I also suggest to change all the IList references to List. As I mentioned above, using foreach operator over IList generates garbage. I know that we should depend on interfaces wherever possible but I think that this is one place, where exception is justified.

from bulletsharp.

AndresTraks avatar AndresTraks commented on September 2, 2024

Ok, cool. Thanks!

I'll do some research on the IList enumeration.

from bulletsharp.

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.