apotapov / gdx-artemis

Fork of artemis entity-system (http://gamadu.com/artemis/) refactored to integrate with Libgdx (http://libgdx.badlogicgames.com/)
Other
53 stars 5 forks source link

(faulty assumption) Entities not inserted into systems #43

Closed junkdog closed 9 years ago

junkdog commented 9 years ago

I recently ran some benchmarks comparing various ECS implemenations - the gdx-artemis entity insertion and removal was surprisingly good; turns out the entities are never inserted into any entity systems.

I've only briefly tried to resolve the problem, but assuming gdx-artemis is backwards API compatible with vanilla artemis, it appears there's a pretty nasty bug in gdx-artemis.

There's a second benchmark, measuring processing speed, which has its entities correctly inserted/removed. Not sure why.

apotapov commented 9 years ago

Good stuff on the benchmarks.

Seems strange to me that the entities are not inserted or removed. I don't see how any games would work if this was the case.

Thanks, for letting me know. Honestly, I haven't touched gdx-artemis in probably half a year. I might get back to it at some point but I'm not working on any java games at the moment.

apotapov commented 9 years ago

Also, looks like the latest artemis-odb is very performant. Great job! If you add events, I won't be able to compete. :)

junkdog commented 9 years ago

I'm stupid, I had changed the random seed which predetermined the entity compositions, never realizing it didn't yield matching entities. Sloppy. I'll re-run the insert/remove benchmarks for all frameworks once I've written some code for autogenerating the charts.

Also, looks like the latest artemis-odb is very performant. Great job! If you add events, I won't be able to compete. :)

Thanks :) You may want to check out DaanVanYperen/artemis-odb-contrib for such things.

apotapov commented 9 years ago

Good stuff! Keep rocking.

apotapov commented 9 years ago

Good stuff with libgdx systems. I had very similar setup in my games.

I just might have to retire gdx-artemis after all this work that you put in.

junkdog commented 9 years ago

Do you remember what kind of optimizations you did pertaining to inserting and removing entities from systems - I expected a more severe performance degradation with higher entity counts, similar to how artemis-odb used to perform. It was actually why I jumped to the conclusion that there was a bug in gdx-artemis, thinking it couldn't be that performant without major refactoring.

In 0.7.0 I got around it by identifying each unique entity composition by an int (compositionId); whenever a new compositionId is encountered, each EntitySystem is queried and caches whether it's interested in that particular compositionId or not.

It'd be interesting if your optimizations could carry over to artemis-odb. Got to do some profiling during the weekend.

apotapov commented 9 years ago

I don't remember exactly what I did. My main concern was always memory management to prevent GC from hogging CPU. The major thing I did was swap all of the data structures both the original ones Artemis and native Java ones to the libgdx ones. Libgdx data structures are built around around memory management, so I thought it would be a good approach. That and pooling everything I could.

That might be where the performance gains come from. I was toying with the idea of using OpenBitSet from Lucene. I did use it in a board game I was building to implement a bitboard (it had more than 64 cells so I couldn't use a long) but didn't get around to putting into gdx-artemis.

I also used a java profiler to figure out where the code was spending a lot of time and optimizing those areas, but I don't think there were any major gains there. If you want, you can get an open source license for that java profiler and just mess around with it to look for hotspots. The benchmark framework that you built would be perfect for it. All you gotta do is email the company about the open source license they are very responsive and I had no problem acquiring one.

guillaume-alvarez commented 9 years ago

Mission Control, provided with Java SDK 7 or 8, is just as good if you need a profiler.

apotapov commented 9 years ago

Good to know. Thanks.

On Sat, Sep 27, 2014 at 2:46 AM, Guillaume Alvarez <notifications@github.com

wrote:

Mission Control, provided with Java SDK 7 or 8, is just as good if you need a profiler.

— Reply to this email directly or view it on GitHub https://github.com/apotapov/gdx-artemis/issues/43#issuecomment-57045409.

apotapov commented 9 years ago

Also, I've been living in the world of lambda programming with Java 8 and loving it. Shame it's not yet supported by Android. (perhaps never will...)

Anyway, I added a note to my repo README to direct folks to your implementation instead.

Best of luck. Keep up the good work!

On Sat, Sep 27, 2014 at 11:13 AM, Andrew Potapov apotapov@gmail.com wrote:

Good to know. Thanks.

On Sat, Sep 27, 2014 at 2:46 AM, Guillaume Alvarez < notifications@github.com> wrote:

Mission Control, provided with Java SDK 7 or 8, is just as good if you need a profiler.

— Reply to this email directly or view it on GitHub https://github.com/apotapov/gdx-artemis/issues/43#issuecomment-57045409 .

junkdog commented 9 years ago

That might be where the performance gains come from. I was toying with the idea of using OpenBitSet from Lucene. I did use it in a board game I was building to implement a bitboard (it had more than 64 cells so I couldn't use a long) but didn't get around to putting into gdx-artemis.

Going to try exchanging BitSet for libgdx's Bits and see if that makes any difference; BitSet looks pretty optimized though. Not anything that surfaces when profiling.

Mission Control, provided with Java SDK 7 or 8, is just as good if you need a profiler.

I always forget about Mission Control. Tend to use visualvm, but it's so-so.

Also, I've been living in the world of lambda programming with Java 8 and loving it. Shame it's not yet supported by Android. (perhaps never will...)

cough retrolambda cough - not sure how well it works with android though, but partial support, at least.

Anyway, I added a note to my repo README to direct folks to your implementation instead. Best of luck. Keep up the good work!

Thanks :)