-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Optimization] skip copying old values during Set's removeAll() #477
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
Conversation
Tests cleared: validation-test/stdlib/Set.swift |
@aschwaighofer Can you please take a look? @dduan Thanks for working on this. Can you please write a small dedicated benchmark? |
@nadavrot Here's result from running the program from the 1st comment on my Mac, each version was ran 4 times.
|
6c350e1
to
4190cbc
Compare
@dduan The gains look suspiciously low. I would expect something higher than 1.3%. Can you step with a debugger (or add printfs, or look at sil) and check that the code does what you think it does? |
@nadavrot I made a mistake in the benchmark, it's fixed now. And the gains don't look low any more 😛. These numbers are from the same MBP (with Netflix playing), the workload is reduced compared to the results I posted above, otherwise the unoptimized version takes forever to finish.
|
That's what I'm talking about! -Dave |
@dduan Excellent. Please commit (if @dabrahams and @gribozavr approve) |
A few questions before accepting the change:
|
As noted in FIXME(performance), when not uniquely referenced, Set.nativeRemoveAll() makes a copy of the memory with same content and only then proceed to remove each element. This patch makes nativeRemoveAll() skip the copying part.
4190cbc
to
b4a7993
Compare
@dabrahams I updated |
@dduan Thanks, but that’s not what I had in mind. |
@dabrahams I happen to have a patch for |
IMO no inspection is needed either way. What am I missing? Also, if there’s no measurable difference, it’s better to share code ;-) |
@dabrahams my other patch re-implemented |
@dduan I think we’re talking past each-other. |
I finally got it :) One thing that confused me is that I'll rework this patch starting at Thank you @dabrahams |
I took another look of this patch and remembered that it optimizes both Dictionary and Set (courtesy of GYP). In terms of code sharing, following through the There's another nuance: a normal call on What do you think @dabrahams? |
on Wed Dec 16 2015, Daniel Duan <notifications-AT-i.8713187.xyz> wrote:
I'm sorry it's been so long, but I'm afraid I don't know what this means.
Ideally -Dave |
Add swift-system
As noted in FIXME(performance), when not uniquely referenced,
Set.nativeRemoveAll() makes a copy of the memory with same content
and only then proceed to remove each element.
This patch makes nativeRemoveAll() skip the copying step.