schteppe / p2.js

JavaScript 2D physics library
Other
2.64k stars 330 forks source link

The performance is worse than box2d.js #322

Open finscn opened 6 years ago

finscn commented 6 years ago

I found the performance of p2.js is worse than box2d.js (only 50%)

There is a test I created:

http://fatidol.com/phy-benchmark/

There are many different box2d.js projects , I chose https://github.com/flyover/box2d.js , Because it includes Google's LiquidFun , I like this feature.

englercj commented 6 years ago

Not sure why, but it looks like tick() & render() is called twice in your p2.js example (unless I'm reading this wrong): image

Whereas with box2d and other libs it is only called once: image

I didn't see anything in the code that would cause two calls, so not sure what I'm seeing here.

finscn commented 6 years ago

@englercj , in my test , it's once .

image

Maybe your chrome's bug ?

finscn commented 6 years ago

these test cases use the same tick-system (in the same file common.js) , there are only some differences in the functions about init-world , render-world & world-step.

photonstorm commented 6 years ago

For me tick is called 3 times, sometimes 4:

chrome_2018-04-27_18-07-39

The slower the machine I try it on, the more ticks I get. The faster the machine, the less ticks. On my desktop gaming PC I get 1 tick solidly. On my laptop, 3 ticks (as above).

So the worse the machine, the more work p2 is being asked to do. Probably as a result of the fixed timestep values it's being fed?

finscn commented 6 years ago

I think because P2.js is slow , it takes multi-tick , not because multi-tick , so slow.

finscn commented 6 years ago

I've update the tick(). Please test again.

Whatever how many times the tick() be called , the p2.js is always slower than box2d .