Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've introduced a variety of optimisations, predominantly around eliminating the need to clone entity identifiers given that they are a string. We now use the smol_str crate as a type alias for
EntityId
(it wasString
).smol_str
has similar characteristics toString
with the major difference being that strings less than 24 bytes are inlined instead of being heap allocated.As a consequence of the optimisations, benchmarking shows that performance has improved 37%. I also see that once some allocations have occurred during the first commands, the happy path of processing commands and emitting events results in no subsequent allocations.
I also used OS X Instruments to profile both CPU and allocations.
There's a README in the benches folder that details how to perform benchmarks, which also provides the ability to compare with previous checkouts. Instructions for using Instruments are also there.
Along the way, I refactored the EntityManager into an async function. While reading more simply, and given that the entity manager isn't required to be shared across tasks, we also reduce a task spawn by one. This is requires an explicit size for the cache, thus eliminating the previous assumptions of "10" etc.