3 ms·
> It uses a lot of polymorphism Are you sure? I have never looked at Java implementation of Box2D used in this benchmark, but Dart version is definitely not t
by mraleph 12y ago
> It uses a lot of polymorphism
Are you sure? I have never looked at Java implementation of Box2D used in this benchmark, but Dart version is definitely not that polymorphic in its hottest function which corresponds to this Java one:
https://github.com/jbox2d/jbox2d/blob/76fa2602a6abcbc557c9d50fc4dce578f4585d40/jbox2d-library/src/main/java/org/jbox2d/dynamics/contacts/ContactSolver.java#L336 https://github.com/jbox2d/jbox2d/blob/76fa2602a6abcbc557c9d5...
It looks like mostly a bunch of floating point math to me with not that many calls out.
Another interesting thing I noticed now is that Java version has all vector math inlined manually, while in Dart version it is not the case (at least not entirely if I remember correctly - we want to write high level code and let optimizer do what it can).
- cromwellian 12y agoNo, I'm not sure. I profiled the hand-written JS function one time and noticed a lot of time spent in polymorphic methods. Also, this coincided with an optimization in GWT to improve hidden class V8 optimizations and speed went up by 300%, so it seemed related to polymorphism. The vector math does look like an apples-to-oranges comparisons. Simple methods like cross-product will inline in GWT as well. The biggie seems to be the elision of the temporary, we'd need something like C++'s return value optimization to get rid of that. I'll try rerunning the bench by adding calls to cross-product to see how it fares. Actually for us, we weren't as interested in comparing the speed to Dart as much as comparing it to the JVM version. The slowdown there is on the order of 50% which isn't bad. In the original thread on G+ I noted there's no way this can be considered an apples-to-apples comparison because they're not running the same code (the port's from Box2D differ), but Joel's whole Box2D benchmark suite kind of rests on this.
- mraleph 12y ago> I'll try rerunning the bench by adding calls to cross-product to see how it fares. btw, if you have a moment I would really appreciate if you tell me how to reproduce +Brandon Donnelson results. It's hard to figure out from those photos which version of GWT should I get from where and what to compile with it. I was not sure if I supposed to check out Joel's code AS IS or I should get it from some other place, etc.
- cromwellian 12y agoIt's been a while, but you'll probably need to built a custom version of GWT using this patch (https://gwt-review.googlesource.com/#/c/8590/ https://gwt-review.googlesource.com/#/c/8590/) as we had to roll back the V8 optimization due to a catastrophic performance regression in IE11. Then you'll need my fork of Joel's repository here: https://github.com/cromwellian/bench2d https://github.com/cromwellian/bench2d I'm not sure they were upstreamed into his. Brandon's results were culled from the informal results I posted in Joel's G+ thread (which he independently verified). From the thread you can see I was quite disbelieving myself and not at all ready to plant a flag, I even implemented a verification in the GWT version to ensure that the final resting state of the system converged to what it was supposed to. Some very tiny patches to GWT (adding dummy random unique properties to prototypes, an optimization to HashMap.put/ArrayList.get, etc) have lead to 300-500% speedups in our benchmark server, meanwhile really complex ones actually slowed things down, or did nothing. For example, I added asmjs output to GWT (where possible in method bodies, not a truly strict-check), I also implemented an optimization which auto-converts Java classes to typedarrays where possible, e.g. class Vec3 { float x, y, z; // getters and setters } Would require the class into a bag of static methods and rewrite the field accesses into indexes into a typed array. This turned out not to be a win when benchmarked on Box2D, probably for other reasons. :(
- kevingadd 12y agoInteresting, why the dummy random unique properties? Some sort of type information/hidden class pollution workaround? Converting classes into typed arrays/typed array buffers is something that seems like it should be awesome but in practice isn't. :( I've tried it extensively in JSIL as well and it seems to only be a win if you have thousands of them in an array - for individual instances you get murdered. Maybe this will get fixed by Typed Objects if they ever land in ES.
- cromwellian 12y agoI am very interested in better ways to transform Java into asmjs, but I think we'll need typed objects and/or some way to deal with garbage collection. The latter is a particular problem, well, if we take the route we did with j2objc, we can just punt and require manual annotations to break reference cycles, implementing our own ref-counting/ARC scheme on top of typed arrays, but it would be nice if someone asmjs and GC could play nicely together, without implementing the Boehm collector. :)