Skip to content

[stdlib] properly promote stack buffer to heap buffer when necessary #20585

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 5 commits into from
Nov 17, 2018

Conversation

lancep
Copy link
Contributor

@lancep lancep commented Nov 14, 2018

rdar://problem/45216800
https://bugs.swift.org/browse/SR-8939

@lancep
Copy link
Contributor Author

lancep commented Nov 14, 2018

@swift-ci please test

@lancep
Copy link
Contributor Author

lancep commented Nov 14, 2018

@swift-ci please benchmark

@lancep lancep requested a review from milseman November 14, 2018 23:54
@swift-ci

This comment has been minimized.

Copy link
Member

@milseman milseman left a comment

Choose a reason for hiding this comment

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

Some code cleanup and testing suggestions

// Our source of code units to normalize is empty and our buffers from
// previous normalizations are also empty.
return nil
}
if segmentBufferCount == 0 && overflowBufferCount == 0 {
if segmentBufferCount == 0 {
//time to fill a buffer if possible. Otherwise we are done, return nil
Copy link
Member

Choose a reason for hiding this comment

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

We don't return nil anymore, do we? What's this comment describing?


expectTrue(set.contains(str))
}

Copy link
Member

Choose a reason for hiding this comment

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

Do we have any expectation on what this should normalize to? Can we write a test for that?

) {
segmentBufferCount = count
} else {
segmentBufferCount = normalizeWithHeapBuffers()
Copy link
Member

Choose a reason for hiding this comment

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

So along this path, we have segment input inside normalizationBuffer, but nothing in segmentBuffer. In the code path below, we don't have input in normalizationBuffer. Is that important?

return segmentHeapBuffer![index]
} else {
let index = segmentBufferIndex
segmentBufferIndex += 1
Copy link
Member

Choose a reason for hiding this comment

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

Common lines can be hoisted

} else {
return nil
return nil
Copy link
Member

Choose a reason for hiding this comment

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

We can simplify this code by putting the return nil as an early return.

Copy link
Member

Choose a reason for hiding this comment

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

E.g.:

guard segmentBufferIndex < segmentBufferCount else { return nil }
// .. now the rest of the function has less indentation and control flow 

@lancep
Copy link
Contributor Author

lancep commented Nov 15, 2018

@swift-ci please test

@lancep
Copy link
Contributor Author

lancep commented Nov 15, 2018

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - b4bc47ca5fd057c91567559091ab15f6d8b30b26

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - b4bc47ca5fd057c91567559091ab15f6d8b30b26

} else {
return nil
return nil
Copy link
Member

Choose a reason for hiding this comment

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

E.g.:

guard segmentBufferIndex < segmentBufferCount else { return nil }
// .. now the rest of the function has less indentation and control flow 

let strNFC = "\u{0336}\u{0308}\u{0301}\u{0357}\u{0313}\u{0314}\u{0351}\u{0300}\u{0300}\u{0300}\u{0314}\u{0357}\u{0301}\u{0308}\u{0301}\u{0315}\u{0360}\u{0061}"
expectEqual(str, strNFC)
}

Copy link
Member

Choose a reason for hiding this comment

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

Were you able to test the case where the previous approach would've skipped over the long segment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this new test caught it.

Copy link
Member

Choose a reason for hiding this comment

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

The concern was that a corner case would cause us to skip a portion of the String. Unfortunately, a test case expressed in terms of string comparison is only testing behavioral consistency but not the actual result. We have _nfcCodeUnits and _withNFCCodeUnits to check exactly this.

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
StringEqualPointerComparison 600 657 +9.5% 0.91x
Hanoi 3486 3787 +8.6% 0.92x (?)

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
CStringLongAscii 423 528 +24.8% 0.80x
StringEqualPointerComparison 588 646 +9.9% 0.91x

Performance: -Onone

TEST OLD NEW DELTA RATIO
Improvement
ArrayOfPOD 859 775 -9.8% 1.11x (?)
StringWordBuilderReservingCapacity 2357 2154 -8.6% 1.09x (?)
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
--------------

@lancep
Copy link
Contributor Author

lancep commented Nov 16, 2018

@swift-ci please test

@lancep
Copy link
Contributor Author

lancep commented Nov 16, 2018

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 2534e9b9923048374d653b169e0676c0345b63e8

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 2534e9b9923048374d653b169e0676c0345b63e8

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -Onone

TEST OLD NEW DELTA RATIO
Improvement
StringUTF16SubstringBuilder 13813 11735 -15.0% 1.18x
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: 8-Core Intel Xeon E5
  Processor Speed: 3 GHz
  Number of Processors: 1
  Total Number of Cores: 8
  L2 Cache (per Core): 256 KB
  L3 Cache: 25 MB
  Memory: 64 GB
--------------

@lancep lancep force-pushed the spotFixForStringCompCrash branch from a29b111 to fc3341e Compare November 16, 2018 19:07
@lancep
Copy link
Contributor Author

lancep commented Nov 16, 2018

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - a29b11138ab35ceb259de02115a74b99b11021ff

@lancep
Copy link
Contributor Author

lancep commented Nov 16, 2018

@swift-ci please benchmark

@lancep
Copy link
Contributor Author

lancep commented Nov 16, 2018

@swift-ci please test

@lancep
Copy link
Contributor Author

lancep commented Nov 16, 2018

@swift-ci please benchmark

@milseman
Copy link
Member

Approved with request for follow PR that tests the actual normalized code units rather than String comparison

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - a29b11138ab35ceb259de02115a74b99b11021ff

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
DropWhileAnySeqCntRange 165 188 +13.9% 0.88x (?)
InsertCharacterEndIndex 151 164 +8.6% 0.92x

Performance: -Onone

TEST OLD NEW DELTA RATIO
Improvement
AnyHashableWithAClass 144000 105500 -26.7% 1.36x
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
--------------

@lancep
Copy link
Contributor Author

lancep commented Nov 16, 2018

@swift-ci please test Linux platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - fc3341e

@lancep
Copy link
Contributor Author

lancep commented Nov 16, 2018

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - fc3341e

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - fc3341e

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