Skip to content

Simplify {Float,Double,Float80}.init(_: String) #28992

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
Jan 6, 2020

Conversation

tbkka
Copy link
Contributor

@tbkka tbkka commented Jan 3, 2020

The original version scanned the entire input string for whitespace and
non-ASCII characters. Both are unnecessary: the C routines we're building on
already stop at non-ASCII characters or non-leading whitespace. So we need only
check the first character for whitespace and verify that all characters are
consumed.

This demonstrates significant improvements for -Onone benchmarks:
about 4k smaller RSS and 3x speedups. I'm not seeing any local
changes to the -O benchmarks, however.

Resolves rdar://33045403

Future: We could further improve this by pushing these checks down into the runtime
stubs and simplifying the ABI so those stubs just returne a success/failure boolean.
In particular, that would avoid inlining these checks into every client.

The original version scanned the entire input string for whitespace and
non-ASCII characters.  Both are unnecessary: the C routines we're building on
already stop at non-ASCII characters or non-leading whitespace.  So we need only
check the first character for whitespace and verify that all characters are
consumed.

This demonstrates significant improvements for -Onone benchmarks:
about 4k smaller RSS and 3x speedups.  I'm not seeing any local
changes to the -O benchmarks, however.

We could further improve this by pushing these checks down into the runtime
stubs and simplifying the ABI so it just returned a success/failure boolean.  In
particular, that could avoid inlining these checks into every client.
But an ABI migration is more work than I have time for right now.
@tbkka
Copy link
Contributor Author

tbkka commented Jan 3, 2020

@swift-ci Please smoke test Linux

@tbkka
Copy link
Contributor Author

tbkka commented Jan 3, 2020

@swift-ci Please smoke test macOS

@compnerd
Copy link
Member

compnerd commented Jan 3, 2020

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

swift-ci commented Jan 3, 2020

Performance: -O

Regression OLD NEW DELTA RATIO
ObjectiveCBridgeStringHash 67 78 +16.4% 0.86x
 
Improvement OLD NEW DELTA RATIO
ParseFloat.Double.Exp 18 12 -33.3% 1.50x
ParseFloat.Float.Exp 17 13 -23.5% 1.31x
ParseFloat.Float.Uniform 40 32 -20.0% 1.25x
ParseFloat.Double.Uniform 59 50 -15.3% 1.18x (?)
ParseFloat.Float80.Exp 54 47 -13.0% 1.15x (?)
EqualSubstringSubstring 42 39 -7.1% 1.08x (?)
LessSubstringSubstring 42 39 -7.1% 1.08x (?)
EqualSubstringSubstringGenericEquatable 42 39 -7.1% 1.08x (?)
EqualSubstringString 42 39 -7.1% 1.08x (?)
LessSubstringSubstringGenericComparable 42 39 -7.1% 1.08x (?)

Code size: -O

Improvement OLD NEW DELTA RATIO
FloatingPointParsing.o 15274 13649 -10.6% 1.12x

Performance: -Osize

Regression OLD NEW DELTA RATIO
FlattenListLoop 4451 5302 +19.1% 0.84x (?)
ObjectiveCBridgeStringHash 68 78 +14.7% 0.87x (?)
NSStringConversion.MutableCopy.UTF8 788 859 +9.0% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
ParseFloat.Double.Exp 27 12 -55.6% 2.25x
ParseFloat.Float.Exp 22 13 -40.9% 1.69x
ParseFloat.Float.Uniform 51 32 -37.3% 1.59x
ParseFloat.Double.Uniform 71 50 -29.6% 1.42x
ParseFloat.Float80.Exp 62 47 -24.2% 1.32x
ObjectiveCBridgeFromNSArrayAnyObjectToString 44700 41200 -7.8% 1.08x (?)
EqualSubstringString 42 39 -7.1% 1.08x (?)
EqualSubstringSubstring 43 40 -7.0% 1.07x (?)
LessSubstringSubstring 43 40 -7.0% 1.07x (?)
EqualStringSubstring 43 40 -7.0% 1.07x (?)
EqualSubstringSubstringGenericEquatable 43 40 -7.0% 1.07x
LessSubstringSubstringGenericComparable 43 40 -7.0% 1.07x

Code size: -Osize

Improvement OLD NEW DELTA RATIO
FloatingPointParsing.o 14696 13257 -9.8% 1.11x

Performance: -Onone

Regression OLD NEW DELTA RATIO
ArrayAppendLatin1 25024 30940 +23.6% 0.81x (?)
ArrayAppendAscii 24752 30464 +23.1% 0.81x (?)
ArrayAppendUTF16 24888 30566 +22.8% 0.81x (?)
ObjectiveCBridgeStringHash 67 78 +16.4% 0.86x (?)
ArrayPlusEqualSingleElementCollection 214508 245387 +14.4% 0.87x (?)
ArrayPlusEqualFiveElementCollection 171643 195101 +13.7% 0.88x (?)
Dictionary4Legacy 1275 1409 +10.5% 0.90x (?)
ArrayOfPOD 1037 1121 +8.1% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
ObjectiveCBridgeStubFromNSDateRef 5370 4280 -20.3% 1.25x (?)
ParseFloat.Double.Exp 49 43 -12.2% 1.14x (?)
ParseFloat.Float.Uniform 74 65 -12.2% 1.14x (?)
ParseFloat.Float80.Exp 89 79 -11.2% 1.13x (?)
ParseFloat.Double.Uniform 93 84 -9.7% 1.11x (?)
DictionaryCompactMapValuesOfCastValue 67284 61128 -9.1% 1.10x (?)
DictionaryBridgeToObjC_Access 1224 1116 -8.8% 1.10x (?)
StringBuilderWithLongSubstring 2850 2620 -8.1% 1.09x (?)
LessSubstringSubstringGenericComparable 50 46 -8.0% 1.09x (?)
EqualSubstringString 51 47 -7.8% 1.09x
StringUTF16SubstringBuilder 17910 16530 -7.7% 1.08x (?)

Code size: -swiftlibs

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

Copy link
Contributor

@stephentyrone stephentyrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Room to make this cleaner still, but good enough start to take now.

@tbkka tbkka merged commit 246d52d into swiftlang:master Jan 6, 2020
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.

4 participants