-
Notifications
You must be signed in to change notification settings - Fork 58
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
Reuse Arc allocation if the ref count is one #9
Conversation
Sorry about the accidental rustfmting. I can revert it but just wanted to post this as-is for now. Before and after for the non-mutating methods
|
Codecov Report
@@ Coverage Diff @@
## master #9 +/- ##
=========================================
+ Coverage 95.24% 95.45% +0.2%
=========================================
Files 12 12
Lines 2084 2090 +6
=========================================
+ Hits 1985 1995 +10
+ Misses 99 95 -4
Continue to review full report at Codecov.
|
Yeah, the speedup can be quite drastic if you have no structural sharing (or not a lot of it). However I would like to keep the API nice and clean. My idea is to have a
|
Is it really worth it to create a separate type just to keep the interface of the "immutable only" types small? The "immutable only" type has nothing preventing them from supporting the methods and there is not that many methods that needs a mutable variant either. For instance, Vector Anyway, I made this mostly out of curiosity of how low the overhead would be with this strategy :) I can clean this |
It is more about having the interface consistent, but I haven't made my mind yet. For now I'm happy with merging this after a cleanup. |
Implemented |
The changes made by rustfmt are still present, but it gave me the oportunity to rustfmt the code in master (I just landed that). So, before you rebase create a
then do
After this commit the changes and you should be able to rebase from master cleanly. |
A bit late but I finally remembered to do the rebase. |
Looks good! I have only a few minor changes, but since I will splitting this in For now I'm happy to land this after a new rebase on master and getting those commits squashed into a single one. |
POC of using `Arc::make_mut` to avoid allocating new `Arc`s unnecesarily. Can speedup mutating operations quite significantly on certain workloads. The same approach could be used on most or all of the other datastructures as well though the difficulty of rewriting may vary. ``` test vector_push_back ... bench: 132,535,931 ns/iter (+/- 6,771,269) test vector_push_back_mut ... bench: 13,759,640 ns/iter (+/- 1,378,950) ```
Done |
Awesome! Thanks! |
POC of using
Arc::make_mut
to avoid allocating newArc
sunnecesarily. Can speedup mutating operations quite significantly on
certain workloads.
The same approach could be used on most or all of the other
datastructures as well though the difficulty of rewriting may vary.
Before
After