How to handle LOTS of static objects

I have a world that has a large number of static objects I want to interact with. Im wondering what the best practices are.
Its a BIG fast moving tile based engine, tiles 400 x 400 pixels wide map 10000 x 10000 all up

- Ive found that rectangles are less processor hungry then circles.
- Whats the best way to deal with 2000 static objects.. I tried a tiled method of instantiating and destroying depending on what tiles were viewed, but this seemed
slower then just having them all created at the start. I am wondering what sort of optimisations box2d has naturally for this sort of thing.... or if there is a smart way of turning them on and off....

Any advice appreciated and gratefully received.

Mark
is there a reason for all the tiles to be separate box2d objects? I have no idea of your game setup, but i have separated the creation of graphic tiles from creation of physical tiles. When the map loads, adjecent tiles of the same kind are built as bigger physical boxes. Is this a possible solution in your situation? I only presume that this is more efficient than many smaller ones.
Yeah, if you can, merge shapes together, as zapp says, it might help.

But 10000x10000 shapes is an absurd number. Box2D is very good at coping with large static worlds, but that is too much. If actual tiles are pretty sparse, I'd give just shoving them all in a shot and seeing how well it copes, but it's not looking too likely. There are sleeping and freezing bodies, which cut down on the calculations required, but Box2D still iterates over them, which is infeasible for for that many shapes.
Basically, there is no built in "scrolling" feature that you seem to be hoping for, you will have to create and delete stuff.
I think I confused you. The world is 10000 x 10000 pixels wide.
Ive found a limit at 500 static objects before I start to get an odd error from
box2d.

Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at Box2D.Collision::b2BroadPhase/CreateProxy()
   at Box2D.Collision.Shapes::b2Shape/CreateProxy()
   at Box2D.Dynamics::b2Body/CreateShape()
   at game.obstacles::Obstacle()
   at game.obstacles::ObstacleManager()
   at Racers/onAddedToStage()


If it is under 500 then this is fine. The speed is quite acceptable for me and I doubt Ill actually have 500 objects on a game screen at once. I am going to explore in more depth dynamic
creation and removal for speed.

Thanks for the replies and advise so far.
Ah, if you only have 500 or so static tiles, you shouldn't be too bad. The assertion you are hitting is just the preset limit of objects in Box2D, you can increase it by setting b2Settings.b2_maxProxies to a larger value than the default of 512. Definitely try that before killing yourself over the dynamic thing.
"b2Settings.b2_maxProxies"

THAT EXPLAINS EVERYTHING

Thanks Boris, that would explain Everything. Im still going with the dynamic add and remove of objects, I was just doing some very dense placement tests with over 512 objects in the immediate area and I couldnt figure out why it was always dying.

Cheers

Mark
I though that I had read somewhere that less bodies, containing more shapes each is faster than more bodies with one shape each.

Am I correct?

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