Skip to content

Removes redundant buffer zeroing in lowercased() and uppercased() by using `init(unsafeUninitializedCapacity:initializingWith:) #30895

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
Jun 9, 2020

Conversation

valeriyvan
Copy link
Contributor

Removes redundant buffer zeroing in lowercased() and uppercased() by using `init(unsafeUninitializedCapacity:initializingWith:)

@theblixguy theblixguy requested a review from milseman April 8, 2020 19:40
@CodaFi
Copy link
Contributor

CodaFi commented Apr 15, 2020

@swift-ci test

@CodaFi
Copy link
Contributor

CodaFi commented Apr 15, 2020

@swift-ci benchmark

@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
StringInterpolationManySmallSegments 8900 11100 +24.7% 0.80x (?)
AngryPhonebook.Strasse.Small 647 744 +15.0% 0.87x (?)
Set.subtracting.Empty.Box 8 9 +12.5% 0.89x (?)
Data.hash.Medium 31 34 +9.7% 0.91x (?)
StringHashing_fastPrenormal 570 620 +8.8% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
LessSubstringSubstring 30 22 -26.7% 1.36x
EqualSubstringSubstringGenericEquatable 30 22 -26.7% 1.36x
EqualSubstringString 30 22 -26.7% 1.36x
LessSubstringSubstringGenericComparable 30 22 -26.7% 1.36x
EqualStringSubstring 31 23 -25.8% 1.35x
EqualSubstringSubstring 30 23 -23.3% 1.30x
StringComparison_longSharedPrefix 357 323 -9.5% 1.11x (?)
ObjectiveCBridgeStubToNSDate2 360 330 -8.3% 1.09x (?)
ArraySetElement 284 263 -7.4% 1.08x (?)
PrefixWhileSequence 178 165 -7.3% 1.08x (?)
ObjectiveCBridgeStubToNSDateRef 2320 2160 -6.9% 1.07x (?)

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
AngryPhonebook.Strasse.Small 654 755 +15.4% 0.87x
StringHashing_fastPrenormal 560 630 +12.5% 0.89x
 
Improvement OLD NEW DELTA RATIO
LessSubstringSubstring 31 23 -25.8% 1.35x
EqualStringSubstring 31 23 -25.8% 1.35x
LessSubstringSubstringGenericComparable 31 23 -25.8% 1.35x (?)
FlattenListFlatMap 4084 3126 -23.5% 1.31x (?)
EqualSubstringSubstring 30 23 -23.3% 1.30x (?)
EqualSubstringSubstringGenericEquatable 30 23 -23.3% 1.30x
EqualSubstringString 30 23 -23.3% 1.30x
Set.subtracting.Empty.Box 9 8 -11.1% 1.12x (?)
StringBuilderLong 1060 970 -8.5% 1.09x (?)
AngryPhonebook 273 252 -7.7% 1.08x (?)
ArraySetElement 283 262 -7.4% 1.08x (?)
Array2D 4544 4208 -7.4% 1.08x (?)

Code size: -Osize

Performance: -Onone

Regression OLD NEW DELTA RATIO
AngryPhonebook.Strasse.Small 745 851 +14.2% 0.88x (?)
 
Improvement OLD NEW DELTA RATIO
LessSubstringSubstring 35 27 -22.9% 1.30x
EqualSubstringSubstringGenericEquatable 34 27 -20.6% 1.26x
EqualSubstringSubstring 35 28 -20.0% 1.25x (?)
EqualStringSubstring 35 28 -20.0% 1.25x
EqualSubstringString 35 28 -20.0% 1.25x
LessSubstringSubstringGenericComparable 34 28 -17.6% 1.21x
ArrayAppendLatin1Substring 34776 31644 -9.0% 1.10x (?)
CharacterLiteralsLarge 377 348 -7.7% 1.08x (?)
Set.subtracting.Empty.Int 83 77 -7.2% 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 mini
  Model Identifier: Macmini8,1
  Processor Name: 6-Core Intel Core i7
  Processor Speed: 3.2 GHz
  Number of Processors: 1
  Total Number of Cores: 6
  L2 Cache (per Core): 256 KB
  L3 Cache: 12 MB
  Memory: 64 GB

output.baseAddress._unsafelyUnwrappedUnchecked,
Int32(output.count),
buf.baseAddress._unsafelyUnwrappedUnchecked,
Int32(buf.count),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: In general, the stdlib code base avoids ad-hoc abbreviations such as “buf” or “ret”; I realize some of these were not created by you, but ideally we wouldn’t introduce more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed variables.

&err))
initializedCount = min(len, uChars.count)
if len > uChars.count {
throw DummyError.dummy
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, who catches this error? Does this code path represent a violation of an invariant or precondition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewritten without throwing.

@valeriyvan valeriyvan requested a review from xwu April 16, 2020 05:43
@milseman
Copy link
Member

This looks much better without the error throwing, thanks!

@xwu
Copy link
Collaborator

xwu commented Apr 17, 2020

@swift-ci benchmark

@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
ObjectiveCBridgeStubFromNSDateRef 4750 5760 +21.3% 0.82x (?)
EqualSubstringSubstring 40 44 +10.0% 0.91x (?)
EqualSubstringSubstringGenericEquatable 40 44 +10.0% 0.91x (?)
EqualSubstringString 40 44 +10.0% 0.91x
EqualStringSubstring 41 45 +9.8% 0.91x (?)
SortStringsUnicode 2870 3110 +8.4% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
Breadcrumbs.MutatedUTF16ToIdx.ASCII 5 4 -20.0% 1.25x (?)

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
String.data.Empty 39 50 +28.2% 0.78x (?)
String.data.Small 42 52 +23.8% 0.81x (?)
String.data.LargeUnicode 137 152 +10.9% 0.90x (?)
EqualSubstringSubstring 41 45 +9.8% 0.91x (?)
LessSubstringSubstring 41 45 +9.8% 0.91x
EqualStringSubstring 41 45 +9.8% 0.91x (?)
EqualSubstringSubstringGenericEquatable 41 45 +9.8% 0.91x (?)
LessSubstringSubstringGenericComparable 41 45 +9.8% 0.91x (?)
SortStringsUnicode 2930 3180 +8.5% 0.92x (?)
AngryPhonebook.Strasse.Small 943 1020 +8.2% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
Diffing.Same 9 8 -11.1% 1.12x (?)

Code size: -Osize

Performance: -Onone

Regression OLD NEW DELTA RATIO
StringToDataMedium 4600 5100 +10.9% 0.90x (?)
EqualSubstringSubstring 47 51 +8.5% 0.92x (?)
LessSubstringSubstring 47 51 +8.5% 0.92x (?)
EqualSubstringSubstringGenericEquatable 47 51 +8.5% 0.92x
LessSubstringSubstringGenericComparable 47 51 +8.5% 0.92x
 
Improvement OLD NEW DELTA RATIO
StringWordBuilder 2780 2580 -7.2% 1.08x (?)
StringWordBuilderReservingCapacity 2710 2530 -6.6% 1.07x (?)

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

@valeriyvan
Copy link
Contributor Author

ping

1 similar comment
@valeriyvan
Copy link
Contributor Author

ping

@xwu
Copy link
Collaborator

xwu commented May 27, 2020

Can you squash the commits (except the one merging master)? Then let's kick off another test.

@valeriyvan valeriyvan force-pushed the RemoveRedundantZeroingString branch from 809dcab to 04e6373 Compare May 27, 2020 20:25
@valeriyvan
Copy link
Contributor Author

Can you squash the commits (except the one merging master)? Then let's kick off another test.

done

@xwu
Copy link
Collaborator

xwu commented May 27, 2020

@swift-ci test

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@xwu
Copy link
Collaborator

xwu commented May 28, 2020

@swift-ci test Linux platform

@swift-ci

This comment has been minimized.

@xwu
Copy link
Collaborator

xwu commented May 28, 2020

@swift-ci smoke test Linux platform

1 similar comment
@xwu
Copy link
Collaborator

xwu commented May 30, 2020

@swift-ci smoke test Linux platform

@xwu
Copy link
Collaborator

xwu commented Jun 1, 2020

@swift-ci test Linux platform

@swift-ci

This comment has been minimized.

@xwu
Copy link
Collaborator

xwu commented Jun 1, 2020

Let's see if this will do it:
@swift-ci clean test Linux platform

@swift-ci
Copy link
Contributor

swift-ci commented Jun 1, 2020

Build failed
Swift Test Linux Platform
Git Sha - 04e6373

@natecook1000
Copy link
Member

@swift-ci Please smoke test

@xwu xwu merged commit 1888534 into swiftlang:master Jun 9, 2020
@valeriyvan valeriyvan deleted the RemoveRedundantZeroingString branch February 20, 2023 08:09
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.

6 participants