Continuos memory usage

I noticed in the testbed that the memory usage displayed continuously fluctuates between two numbers.
Even when the dynamic bodies in example are at sleeping.
Why is this so?
It seems some variables are generated in every step and then garbage collected after some time.
Is this true.
Is there any way to disable this and make them permanent.
Yes, it is true. No, there's little you can do about it, without major work. There's a java thread on reducing this sort of things somewhere, I suggest you search for it.
well, i will search for it . This problem is killing my project. I have a stutter every time these extra variables are garbage collected.
I will search for the other thread. It would be quite helpful if someone points me to it.
Neways ne other help / tweak is highly appreciated.

i found a thread "box2djava". It seems to discuss about making variables local.
This i think is opposite to what i want. I want minimum local variables and don't mind a large memory usage. I want to avoid the garbage collection that happens every few seconds. it makes my application jerky.
Diving into box2d, finally.
I have been working on it for some time but never went in to uunderstand it.
Now that i have started getting in i m a bit puzzled.
Can anyone provide me with some links for the inner workings of box2d.

I have studied ape before and have some knowledge of separate axis theorem and its usage in collision detection.
Is box2d based on the same or is it different.
Really not sure about broadphase collision detection. What exactly is it?
There's not much on the internal code. Try Erin's original slides: http://www.gphysics.com/downloads and what little the wiki has: http://www.box2d.org/wiki/index.php?tit ... disclaimer (this includes an explanation of the broadphase)

Separating Axis Theorem is still used. It's in b2Collision.as, and is called from b2PolyContact.

The Java version has to deal with multithreading, but has a GC that can better cope with local things. In AS3, you'd declare a private static variable to be re-used, you can see this in a couple of places. Or better, inline the operation.

But an equally large problem is objects of short duration (one Step) that are not necessarily localizable - these are easily identified as they use b2StackAllocator in the original C++. These would all need to be rewritten with pools.

You can see there's a lot to do. It's not been a high priority amongst development, but if you'd like to see it improve, it's certainly the sort of thing that can see incremental improvement, and with plenty of low hanging fruit. I suggest you start with making a fixed test scenario, and profile it, before attempting to make any improvements - Flash is notoriously fickle on what optimizations actually translate to real world effect.
BorisTheBrave wrote:
The Java version has to deal with multithreading, but has a GC that can better cope with local things.

This is definitely true, but it's worth pointing out that even using a recent JVM with the advanced GC that it has (which is highly optimized for short-lived objects), the primary bottleneck for JBox2d is still temporary object allocation, at least once you take graphics out of the equation. So to me, "optimizing" is pretty much equivalent to getting rid of those allocations/gcs, and this is likely even more true using AS3.

Quote:
You can see there's a lot to do. It's not been a high priority amongst development, but if you'd like to see it improve, it's certainly the sort of thing that can see incremental improvement, and with plenty of low hanging fruit.

Indeed. Focus on the contact solver and collision detection and you can get some unbelievable speed gains with very little effort; I wouldn't be surprised to hear that a couple hours work could double the physics speed (that has happened a couple of times now with Java - the latest round, which I did not do myself, rocketed my benchmark test case from 250 fps to 450 fps, and before that even happened I'd already done most of the "easy" inlinings!). Just don't waste time cutting out things that are called once per-body or anything like that (i.e. ignore the b2Body class completely), the ones you want to worry about are the things that happen per-contact-per-iteration, at least at first.

One thing that might make things a little trickier is that in Java you can use Eclipse to get the harder inlines done (a lot of the stuff involving matrix transformations can be nasty to do by hand), since it's able to automatically inline stuff; I'm not sure if the AS3 has equivalent functionality, which might slow things down a little bit.
I'd be really careful with determining speed improvements based on frame rate... It can be extrememly misleading.
I'm not saying ewjordan is wrong with his calculation in speed improvement, in fact he's pretty much right on. At 250 FPS the physics is taking 4 ms per frame to complete. At 450, its 2.22 ms. However, its pretty easy to not realize that a 200 fps jump there only represents a 100% increase, while the same could be said for a jump with a 30 fps jump from 30fps( 33.3 ms ) to 60 fps( 16.6 ms ).

With that said, I'm really glad this thread came up. Gives me a good idea of where to start in making performance improvements to the as3 port. Time for me to give something back I think.
Exactly right - once a reasonably complex physics scene is simulating at 400+ fps, something else will almost always be your bottleneck, so there are certainly diminishing returns (the scene I chose involved more stacking and objects than most realistic applications). In Java, the only reason I want to go further is that on non-desktop platforms, GC is much slower, so zero-garbage is almost a necessity for a library; we still don't have a mobile port, but it's under consideration, so I'm thinking ahead to that.

IMO the thing to do is to shoot for a point where the graphics will almost always "cost" more than the physics for fairly simple graphical objects, because once you're there, people aren't going to push much further anyhow due to the graphical limitations (you're within a small constant factor of the highest theoretical object count given the external constraints). There's probably quite a way to go with the AS3 port before getting there, so I think a lot of people would be very appreciative of anything you could contribute.
Thank you for all the reponse.
My personal experience in optimisation is very basic.
So i m not sure how far will i reach.
But i have to do this one way or the other. I will update my progress time to time on this thread.
Till then thank you for the help so far.
Went through some part of the engine.
Its just awesome.
I have been using it for quiet some time now but never went inside it.
Now that i m it seems absolutely amazing.
Tried some changes internally but it seems that optimization is going to b a difficult job.

Firstly as most of u might know, the as3 GC is very vague. i.e. very little knowledge is available regarding it. But from what i could gather around the net, i found that not much can be done in as3. So i m really confused whether i should try it out. Basic experiments have shown me that it is very difficult to guess the behavior of GC. Bringing some variables out if redeclaration doesn't seem to help much.
So if anyone has a better idea of the GC, please let me know.

P.S. Already been through G Skinner's blogs on memory management in as3. Also used active graph, WS monitor.

Original thread: https://box2d.org/forum/viewtopic.php?t=2917