Skip to content

[stdlib] Dictionary.updateValue(_:,forKey:): Don’t overwrite the existing key #19500

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

Merged
merged 1 commit into from
Sep 26, 2018

Conversation

lorentey
Copy link
Member

@lorentey lorentey commented Sep 24, 2018

updateValue(_:, forKey:) currently replaces the old key, which is undocumented, unnecessary and somewhat surprising. The previous incarnation of Dictionary implemented updates this way because of a technical detail; this wrinkle is now eliminated.

rdar://problem/32144087

This change is detectable for types where equality is not the same as identity, so this is technically source breaking. Therefore at minimum, this requires a discussion on the fora before landing.

I know of no use cases where the old behavior was actually desirable; most/all practical code that would care about this seem to prefer to leave the old key in place.

…ting key

Replacing the old key with the new is unnecessary and somewhat surprising. It is also harmful to some usecases.

rdar://problem/32144087
@lorentey
Copy link
Member Author

@swift-ci please test

@airspeedswift
Copy link
Member

I don't think we'd classify this as falling under the source-breaking umbrella so pretty sure you're safe.

@lorentey
Copy link
Member Author

This may speed up the Dictionary subscript setter a bit.

@swift-ci please smoke benchmark

@lorentey lorentey changed the title 🛑[stdlib] Dictionary.updateValue(_:,forKey:): Don’t overwrite the existing key [stdlib] Dictionary.updateValue(_:,forKey:): Don’t overwrite the existing key Sep 26, 2018
@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
IterateData 1563 1732 +10.8% 0.90x (?)
Improvement
Dictionary4OfObjects 377 348 -7.7% 1.08x

Code size: -O

TEST OLD NEW DELTA RATIO
Improvement
DictionaryKeysContains.o 20535 20183 -1.7% 1.02x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
IterateData 1649 1834 +11.2% 0.90x (?)
Improvement
Dictionary4OfObjects 469 413 -11.9% 1.14x

Code size: -Osize

TEST OLD NEW DELTA RATIO
Improvement
DictionaryKeysContains.o 18247 17895 -1.9% 1.02x
How to read the data The 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
  Model Name: Mac Pro
  Model Identifier: MacPro6,1
  Processor Name: 12-Core Intel Xeon E5
  Processor Speed: 2.7 GHz
  Number of Processors: 1
  Total Number of Cores: 12
  L2 Cache (per Core): 256 KB
  L3 Cache: 30 MB
  Memory: 64 GB

@lorentey
Copy link
Member Author

Yeah, the speedup is mostly below the reporting threshold.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants