Skip to content

[stdlib] Finalize one-shot hashing interface #19495

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 2 commits into from
Sep 24, 2018

Conversation

lorentey
Copy link
Member

_rawHashValue(seed:) is an underscored Hashable requirement with a default implementation, introduced earlier for 5.0. It speeds up hashing of small-sized keys by eliminating some resiliency overhead.

  • Don’t expose the raw execution seed to _rawHashValue.
  • Change the type of _rawHashValue’s seed from (UInt64,UInt64) to a single Int. Working with a pair of UInt64s is unwieldy, and overkill in practice. Int as a seed also integrates nicely with Int as a hash value.
  • Remove _HasherCore._generateSeed(). Instead, simply call finalize() on a copy of the hasher to get a seed suitable for _rawHashValue.
  • Update Set and Dictionary to store a single Int as the seed value.

Note that this doesn’t affect the core hasher, which still mixes in the actual 128-bit execution seed during its initialization. To reduce the potential of confusion, use the name rawSeed to refer to an actual 128-bit seed value.

rdar://problem/44724660

- Don’t expose the raw execution seed to _rawHashValue.
- Change the type of _rawHashValue’s seed from (UInt64,UInt64) to a single Int. Working with a pair of UInt64s is unwieldy, and overkill in practice. Int as a seed also integrates nicely with Int as a hash value.
- Remove _HasherCore._generateSeed(). Instead, simply call finalize() on a copy of the hasher to get a seed suitable for _rawHashValue.
- Update Set and Dictionary to store a single Int as the seed value.

Note that this doesn’t affect the core hasher, which still mixes in the actual 128-bit execution seed during its initialization. To reduce the potential of confusion, use the name “rawSeed” to refer to an actual 128-bit seed value.
@lorentey
Copy link
Member Author

@swift-ci please test

@lorentey
Copy link
Member Author

@swift-ci please smoke benchmark

@lorentey
Copy link
Member Author

@swift-ci please smoke test compiler performance

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Improvement
Dictionary4 312 283 -9.3% 1.10x
RandomDoubleLCG 2171 2028 -6.6% 1.07x (?)

Code size: -Osize

TEST OLD NEW DELTA RATIO
Regression
HashQuadratic.o 6015 6123 +1.8% 0.98x

Performance: -Onone

TEST OLD NEW DELTA RATIO
Regression
Histogram 5463 6558 +20.0% 0.83x
CaptureProp 292206 341527 +16.9% 0.86x
CharIndexing_tweet_unicodeScalars 629536 706321 +12.2% 0.89x
CharIndexing_japanese_unicodeScalars 381846 428216 +12.1% 0.89x
CharIndexing_punctuated_unicodeScalars 71219 79685 +11.9% 0.89x
CharIndexing_ascii_unicodeScalars 321179 357909 +11.4% 0.90x
CharIndexing_russian_unicodeScalars 266235 296312 +11.3% 0.90x
RGBHistogram 21540 23419 +8.7% 0.92x
Improvement
ArrayOfGenericPOD2 1180 1067 -9.6% 1.11x (?)
ArrayOfPOD 859 780 -9.2% 1.10x
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

The improvements seem accidental. Dictionary4 tests multi-component keys, but that's very unlikely to care about the width of the seed.

The -Onone histogram regression implies there might be an extra uninlined function call. I don't think it matters.

@swift-ci
Copy link
Contributor

Build comment file:

Summary for master smoketest

Unexpected test results, excluded stats for Kingfisher, ReactiveCocoa

No regressions above thresholds

Debug

debug brief

Regressed (0)
name old new delta delta_pct
Improved (0)
name old new delta delta_pct
Unchanged (delta < 1.0% or delta < 100.0ms) (3)
name old new delta delta_pct
Frontend.NumInstructionsExecuted 240,254,561,001 239,950,571,646 -303,989,355 -0.13%
LLVM.NumLLVMBytesOutput 9,529,792 9,528,668 -1,124 -0.01%
time.swift-driver.wall 26.6s 26.6s -37.2ms -0.14%

debug detailed

Regressed (0)
name old new delta delta_pct
Improved (0)
name old new delta delta_pct
Unchanged (delta < 1.0% or delta < 100.0ms) (23)
name old new delta delta_pct
AST.NumImportedExternalDefinitions 5,914 5,914 0 0.0%
AST.NumLoadedModules 1,510 1,510 0 0.0%
AST.NumTotalClangImportedEntities 18,273 18,273 0 0.0%
AST.NumUsedConformances 1,344 1,344 0 0.0%
IRModule.NumIRBasicBlocks 32,497 32,497 0 0.0%
IRModule.NumIRFunctions 16,732 16,732 0 0.0%
IRModule.NumIRGlobals 14,487 14,487 0 0.0%
IRModule.NumIRInsts 445,473 445,473 0 0.0%
IRModule.NumIRValueSymbols 29,939 29,939 0 0.0%
LLVM.NumLLVMBytesOutput 9,529,792 9,528,668 -1,124 -0.01%
SILModule.NumSILGenFunctions 7,845 7,845 0 0.0%
SILModule.NumSILOptFunctions 10,595 10,595 0 0.0%
Sema.NumConformancesDeserialized 33,986 33,986 0 0.0%
Sema.NumConstraintScopes 72,125 72,125 0 0.0%
Sema.NumDeclsDeserialized 270,831 270,791 -40 -0.01%
Sema.NumDeclsValidated 16,641 16,641 0 0.0%
Sema.NumFunctionsTypechecked 7,044 7,044 0 0.0%
Sema.NumGenericSignatureBuilders 11,099 11,099 0 0.0%
Sema.NumLazyGenericEnvironments 61,352 61,373 21 0.03%
Sema.NumLazyGenericEnvironmentsLoaded 7,529 7,529 0 0.0%
Sema.NumLazyIterableDeclContexts 45,596 45,596 0 0.0%
Sema.NumTypesDeserialized 115,717 115,590 -127 -0.11%
Sema.NumTypesValidated 14,185 14,185 0 0.0%

Release

release brief

Regressed (0)
name old new delta delta_pct
Improved (0)
name old new delta delta_pct
Unchanged (delta < 1.0% or delta < 100.0ms) (3)
name old new delta delta_pct
Frontend.NumInstructionsExecuted 234,379,549,153 234,145,635,307 -233,913,846 -0.1%
LLVM.NumLLVMBytesOutput 10,587,636 10,584,604 -3,032 -0.03%
time.swift-driver.wall 43.6s 43.5s -104.4ms -0.24%

release detailed

Regressed (0)
name old new delta delta_pct
Improved (0)
name old new delta delta_pct
Unchanged (delta < 1.0% or delta < 100.0ms) (23)
name old new delta delta_pct
AST.NumImportedExternalDefinitions 1,383 1,383 0 0.0%
AST.NumLoadedModules 100 100 0 0.0%
AST.NumTotalClangImportedEntities 4,767 4,743 -24 -0.5%
AST.NumUsedConformances 1,346 1,346 0 0.0%
IRModule.NumIRBasicBlocks 35,373 35,373 0 0.0%
IRModule.NumIRFunctions 15,052 15,052 0 0.0%
IRModule.NumIRGlobals 13,851 13,843 -8 -0.06%
IRModule.NumIRInsts 339,191 339,019 -172 -0.05%
IRModule.NumIRValueSymbols 27,839 27,831 -8 -0.03%
LLVM.NumLLVMBytesOutput 10,587,636 10,584,604 -3,032 -0.03%
SILModule.NumSILGenFunctions 6,074 6,074 0 0.0%
SILModule.NumSILOptFunctions 9,004 9,004 0 0.0%
Sema.NumConformancesDeserialized 17,126 17,125 -1 -0.01%
Sema.NumConstraintScopes 70,723 70,723 0 0.0%
Sema.NumDeclsDeserialized 51,550 51,528 -22 -0.04%
Sema.NumDeclsValidated 10,362 10,362 0 0.0%
Sema.NumFunctionsTypechecked 4,360 4,360 0 0.0%
Sema.NumGenericSignatureBuilders 2,523 2,523 0 0.0%
Sema.NumLazyGenericEnvironments 11,122 11,127 5 0.04%
Sema.NumLazyGenericEnvironmentsLoaded 1,628 1,628 0 0.0%
Sema.NumLazyIterableDeclContexts 6,034 6,034 0 0.0%
Sema.NumTypesDeserialized 29,527 29,500 -27 -0.09%
Sema.NumTypesValidated 7,103 7,103 0 0.0%

@lorentey lorentey merged commit 6cef0be into swiftlang:master Sep 24, 2018
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.

2 participants