-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Dictionary.values: Replace setter with _modify #19497
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
[stdlib] Dictionary.values: Replace setter with _modify #19497
Conversation
This should enable in-place modification of the Values view, which should greatly improve the performance of code like this: dictionary.values[index] = newValue
@swift-ci please smoke test |
@swift-ci please smoke benchmark |
I think we actually have some benchmarks for this. |
Build comment file:Build failed before running benchmark. |
Oops, |
@swift-ci please smoke benchmark |
@swift-ci please smoke test |
Interesting. This is similar to yielding a Should there be a (debug?) postcondition that the user didn't replace one instance of |
I guess it is slightly weird that assigning to dict.values = someOtherDict.values // same as dict = someOtherDict It seems technically difficult to verify the identity doesn't change. We could remember the raw bit pattern for it, but it wouldn't be foolproof -- the yieldee could end up releasing it and allocating a new one at the same address. |
Oh, right, replacing the values replaces the entire dictionary, so it is safe, if confusing. A debug trap might be useful for a case where someone mistakenly thinks it does something different though. |
Build comment file:Performance: -O
Performance: -Osize
Performance: -Onone
How to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the regressions before you merge the PR. Noise: Sometimes the performance results (not code size!) contain false alarms. Unexpected regressions which are marked with '(?)' are probably noise. If you see regressions which you cannot explain you can try to run the benchmarks again. If regressions still show up, please consult with the performance team (@eeckstein). Hardware Overview
|
The setter didn't include a trap, so adding it in _modify would technically be a source-breaking change. We should probably make a separate issue for it. |
Yeah it's not a new issue for this change. |
This should enable in-place modification of the
Values
view, which should greatly improve the performance of code like this:https://bugs.swift.org/browse/SR-5258 / rdar://problem/44725826