Skip to content

[SE-0163] Migrate from deprecated Unicode APIs (part 3) #33175

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

Conversation

benrimmington
Copy link
Contributor

Follow-up to: #32920

var buffer: UInt64 = 0
var i = 0
let sink: (UInt8) -> Void = {
#if _endian(little)
buffer = buffer | (UInt64($0) << (UInt64(i) * 8))
#else
buffer = buffer | (UInt64($0) << (UInt64(7-i) * 8))
#endif
i += 1
}
UTF8.encode(unicodeScalar, into: sink)
return body(UnsafeBufferPointer(
start: UnsafePointer(Builtin.addressof(&buffer)),
count: i))
return unicodeScalar.withUTF8CodeUnits { body($0) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is using the internal Unicode.Scalar.withUTF8CodeUnits(_:) method, which has been ABI-public since Swift 5.0 — I assume it will also be available in the bundled stdlib (e.g. when targeting macOS 10.9).

Copy link
Member

Choose a reason for hiding this comment

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

Yep, those were built from the same sources!

(It's unfortunate that this non-public entry point is missing its leading underscore.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(There was also a fix in Swift 5.1 for big-endian platforms.)

// CHECK: @"$ss12StaticStringV14withUTF8BufferyxxSRys5UInt8VGXElFyAEcfU_"
// CHECK: @"$ss12StaticStringV14withUTF8BufferyxxSRys5UInt8VGXElFxAFXEfU_"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test now has a different closure #1 type in its mangled name.

  • Old swift-demangle result:

    $ss12StaticStringV14withUTF8BufferyxxSRys5UInt8VGXElFyAEcfU_ ---> 
    closure #1 (Swift.UInt8) -> () in 
    Swift.StaticString.withUTF8Buffer<A>((Swift.UnsafeBufferPointer<Swift.UInt8>) -> A) -> A
    
  • New swift-demangle result:

    $ss12StaticStringV14withUTF8BufferyxxSRys5UInt8VGXElFxAFXEfU_ ---> 
    closure #1 (Swift.UnsafeBufferPointer<Swift.UInt8>) -> A in 
    Swift.StaticString.withUTF8Buffer<A>((Swift.UnsafeBufferPointer<Swift.UInt8>) -> A) -> A
    

@benrimmington
Copy link
Contributor Author

@swift-ci Please smoke test

Copy link
Member

@lorentey lorentey left a comment

Choose a reason for hiding this comment

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

This looks good to me! 👍 (Cc @milseman, too)

var buffer: UInt64 = 0
var i = 0
let sink: (UInt8) -> Void = {
#if _endian(little)
buffer = buffer | (UInt64($0) << (UInt64(i) * 8))
#else
buffer = buffer | (UInt64($0) << (UInt64(7-i) * 8))
#endif
i += 1
}
UTF8.encode(unicodeScalar, into: sink)
return body(UnsafeBufferPointer(
start: UnsafePointer(Builtin.addressof(&buffer)),
count: i))
return unicodeScalar.withUTF8CodeUnits { body($0) }
Copy link
Member

Choose a reason for hiding this comment

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

Yep, those were built from the same sources!

(It's unfortunate that this non-public entry point is missing its leading underscore.)

@lorentey
Copy link
Member

@swift-ci benchmark

@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
Set.isSuperset.Seq.Empty.Int 47 55 +17.0% 0.85x (?)
Set.isDisjoint.Seq.Int.Empty 45 52 +15.6% 0.87x (?)
Set.isSubset.Seq.Empty.Int 76 84 +10.5% 0.90x (?)
ObjectiveCBridgeStringHash 81 88 +8.6% 0.92x (?)
Set.subtracting.Empty.Int 26 28 +7.7% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
Breadcrumbs.MutatedUTF16ToIdx.Mixed 314 273 -13.1% 1.15x (?)
Breadcrumbs.MutatedIdxToUTF16.Mixed 321 280 -12.8% 1.15x

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
Set.isSuperset.Seq.Empty.Int 46 52 +13.0% 0.88x (?)
UTF8Decode_InitFromData 146 165 +13.0% 0.88x (?)
StringComparison_ascii 373 408 +9.4% 0.91x (?)
UTF8Decode_InitFromBytes 160 174 +8.7% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
Breadcrumbs.MutatedUTF16ToIdx.Mixed 316 274 -13.3% 1.15x (?)
Breadcrumbs.MutatedIdxToUTF16.Mixed 321 279 -13.1% 1.15x (?)
FlattenListFlatMap 2768 2439 -11.9% 1.13x (?)
Array2D 4832 4384 -9.3% 1.10x
ObjectiveCBridgeStubToNSDateRef 2380 2220 -6.7% 1.07x (?)
DropFirstCountableRange 15 14 -6.7% 1.07x (?)

Code size: -Osize

Performance: -Onone

Regression OLD NEW DELTA RATIO
StringFromLongWholeSubstring 9 10 +11.1% 0.90x (?)
 
Improvement OLD NEW DELTA RATIO
Breadcrumbs.MutatedUTF16ToIdx.Mixed 330 288 -12.7% 1.15x (?)
Breadcrumbs.MutatedIdxToUTF16.Mixed 337 295 -12.5% 1.14x (?)
ArrayAppendLatin1Substring 31608 29232 -7.5% 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

@milseman
Copy link
Member

milseman commented Aug 6, 2020

LGTM

@benrimmington benrimmington merged commit d3f0de8 into swiftlang:master Aug 6, 2020
@benrimmington benrimmington deleted the se-0163-migration-3 branch August 6, 2020 22:45
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