-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V8 optimization #5
Comments
I also can't see a reason to use the inheritance class. I haven't looked at how it works, but I wouldn't be surprised if it completely destroyed all V8's hidden class optimisation. That said, as far as I can see CES.js doesn't require you to use the inheritance class at all. This should work (not tested):
And the same thing for Systems (EDIT: except you need to define I'm also wandering about optimisation in general. For example, it seems like for every System, for every world tick the following occurs:
So an array is being created by every System at every world tick? For my use case this means literally thousands of unnecessary allocations per second. Wouldn't it be better to just return the linked list (i.e. remove the Also, I'm not a pro with any of this stuff, but I think component pooling would be an absolute must if this library is going to be used for anything where performance is important (like thousands of components being created/destoyed every tick). As far as I can tell, the following additions/alterations to CES.js would be required for component pooling:
I'm not sure about Entity pooling. I think some profiling would be useful to see whether it's worth it. I really like the cleanness/simplicity of CES.js but just a bit of optimisation would make this library useful for larger, more performance-oriented projects. |
Also, correct me if I'm wrong, but it looks like these two statements produce different families:
So unless I've missed something, just adding a sort in
|
Hi @josephrocca, Thank you for your insightful suggestions. The reason that I chose John Resig's class implementation is that it provides a very convenient API to define classes, which is quite useful for games development. Many notable JS game engines, such as ImpactJs, MelonJs, etc, all use similar mechanism to implement classes. Though I admit that it's an anti-pattern when it comes to v8 optimization, the initial objective of ces.js was more focused on developer-friendliness rather than performance. I would need to do some profiling in order to determine whether it's worth to switch to the traditional class definition. As for the following example you provided, unfortunately it's not performant either, as every instance will have separate copies of the methods defined on itself, instead of sharing the methods by prototypes. function Health(maxHealth) {
this.name = 'health';
this.health = this.maxHealth = maxHealth;
this.isDead = function () {
return this.health <= 0;
}
this.receiveDamage = function (damage) {
this.health -= damage;
}
}
//and later:
hero.addComponent(new Health(100)); Regarding object pooling and reusing, yes, it will be really helpful to reduce GC overhead. I'll consider implement that. Converting the linked lists to arrays is, again, due to the aim to provide a user-friendly API, as most JS programmers would feel more comfortable to work on a native array, instead of learning the specific implementation of the linked list that ces.js provides. Nonetheless, I could define methods like forEach on the list, so that it would be more approachable to use. Finally, the following two statements are producing different families, which is definitely a bug and thanks for pointing out. world.getEntities('Position', 'Velocity');
world.getEntities('Velocity', 'Position'); Thank you again and happy hacking :) |
Is CES.js optimized for the v8 javascript engine? I noticed you were using John Resig's inheritance class for extending your objects, but in my own projects I've found that really bogs down the code optimization. I'm actually moving to using an entity component system to get away from using inheritance chains, but I see you're using them in your engine. Do you have any performance measures that you could show me?Just to ensure that If I go with CES, I won't be adding just another inheritance layer on top of my already existing one. Thanks!
The text was updated successfully, but these errors were encountered: