Skip to content
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

Optimisations and benchmarking #6

Merged
merged 3 commits into from Aug 14, 2023
Merged

Optimisations and benchmarking #6

merged 3 commits into from Aug 14, 2023

Conversation

huntc
Copy link
Collaborator

@huntc huntc commented Aug 14, 2023

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 was String). smol_str has similar characteristics to String 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.

Simplifies the entity manager by flattening it into an async function. Entity managers are not shared, so this approach seems more reasonable. Spawning the task is then left to the discretion of the caller, which then becomes more direct and comprehensible. We also get the slight optimisation of one less spawn and its associated allocations.
Measures the time taken to produce 10K events and process them.
@huntc huntc marked this pull request as ready for review August 14, 2023 06:49
@huntc huntc requested a review from patriknw August 14, 2023 06:49
@huntc huntc self-assigned this Aug 14, 2023
@huntc huntc added the enhancement New feature or request label Aug 14, 2023
Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@huntc huntc merged commit 12f4f48 into main Aug 14, 2023
1 check passed
@huntc huntc deleted the optimise branch August 14, 2023 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants