-
Notifications
You must be signed in to change notification settings - Fork 7
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
Cache #4
base: master
Are you sure you want to change the base?
Cache #4
Conversation
@@ -37,6 +40,8 @@ EntityManager.prototype.create = function() { | |||
var entity = this._entityInst[id] | |||
this._entityFlag[id] = ENTITY_ALIVE | |||
|
|||
entity._cacheIndex = this._entityCache[0].push(entity) - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not add anything to the entity.
Instead create an Int32Array
to store indexes like _entityMask
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
Fyi, I tried preallocating an array based on the amount of entities the query will return. The speedup was roughly 2-3x for 100k entities 50k returned |
Can you rebase on master? |
Sure thing. |
@@ -22,6 +22,9 @@ function EntityManager(components, storage) { | |||
|
|||
this._entityPool = [] | |||
this._entityCounter = 0 | |||
|
|||
this._entityCache = {} | |||
this._entityCache[0] = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be optimized:
this._entityCache = FastMap()
this._entityCache[0] = []
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So do you suggest I add fast.js to the project and require it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Next to utils.js
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting:
/home/user/Projects/mq_makr/makr/lib/fast.js:10
ForceEfficientMap.prototype = self
^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed on the gist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, wow didn't notice the missing brackets
Well let's finish the PR, add some tests to ensure there a no duplicates and we should be good |
I've added several tests which seem to confirm it's working correctly. But I have something I want to still add to it which would effectively get around the .push() problem. I predict this will have a very big impact on the performance. |
Initial numbers (All tests pass, including the new ones):
As you see, it will be independent of the amount of entities. Before: After: This is something I'd like to fix by scheduling the cache invalidations for the next query somehow. I'd like to see the numbers back to the old ones ;). Let me know what you think. All the other numbers stayed the same btw. |
Can this be merged? |
@eranimo I don't think so. I'm not fully satisfied by this change. While the performance improvement is huge for |
This caches entities by their mask