Skip to content

Fix bounds check in bridged ASCII String comparison #24457

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

Conversation

Catfish-Man
Copy link
Contributor

@Catfish-Man Catfish-Man commented May 3, 2019

Fixes rdar://problem/50407214

'count' is the UTF8 count of self, and the only String that we've proven is ASCII at this point is 'other', so 'count' can be greater than 'length'.

@Catfish-Man Catfish-Man requested a review from milseman May 3, 2019 00:46
@Catfish-Man Catfish-Man self-assigned this May 3, 2019
@Catfish-Man
Copy link
Contributor Author

@swift-ci please test

@Catfish-Man Catfish-Man requested a review from airspeedswift May 3, 2019 00:47
@swift-ci
Copy link
Contributor

swift-ci commented May 3, 2019

Build failed
Swift Test OS X Platform
Git Sha - de23660888e21c6ba0f46c7eb4aa13a6aed6b2cf

@swift-ci
Copy link
Contributor

swift-ci commented May 3, 2019

Build failed
Swift Test Linux Platform
Git Sha - de23660888e21c6ba0f46c7eb4aa13a6aed6b2cf

@airspeedswift
Copy link
Member

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

swift-ci commented May 3, 2019

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
Calculator 135 153 +13.3% 0.88x (?)
OpenClose 61 67 +9.8% 0.91x (?)
Chars2 3100 3400 +9.7% 0.91x (?)

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
Calculator 140 160 +14.3% 0.88x
PrefixCountableRangeLazy 15 17 +13.3% 0.88x (?)
OpenClose 65 71 +9.2% 0.92x (?)
Chars2 3150 3400 +7.9% 0.93x (?)

Performance: -Onone

TEST OLD NEW DELTA RATIO
Regression
DataAppendDataLargeToLarge 17800 24200 +36.0% 0.74x (?)
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: 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

@Catfish-Man
Copy link
Contributor Author

Test failures are due to forcing ASAN on for this test. Asking some folks what to do about that

@aroben
Copy link

aroben commented May 3, 2019

Do you think those performance regressions are real? I wonder why this change would hurt performance; aren't we passing a smaller byte count to memcmp now?

@Catfish-Man Catfish-Man force-pushed the two-by-two-length-of-blue branch from de23660 to e672675 Compare May 3, 2019 20:42
@Catfish-Man
Copy link
Contributor Author

The perf regressions aren't real, none of those tests use the code in question

@Catfish-Man
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented May 3, 2019

Build failed
Swift Test OS X Platform
Git Sha - de23660888e21c6ba0f46c7eb4aa13a6aed6b2cf

@aroben
Copy link

aroben commented May 3, 2019

Yikes, they are very large-looking unreal regressions.

@swift-ci
Copy link
Contributor

swift-ci commented May 3, 2019

Build failed
Swift Test Linux Platform
Git Sha - de23660888e21c6ba0f46c7eb4aa13a6aed6b2cf

@Catfish-Man Catfish-Man force-pushed the two-by-two-length-of-blue branch from e672675 to 7787385 Compare May 3, 2019 22:53
@Catfish-Man Catfish-Man force-pushed the two-by-two-length-of-blue branch from 7787385 to 008699e Compare May 3, 2019 22:56
@Catfish-Man
Copy link
Contributor Author

@milseman pointed out an improved approach that makes this clearer and is likely a perf win at the same time :)

@Catfish-Man
Copy link
Contributor Author

@swift-ci please benchmark

@Catfish-Man
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented May 3, 2019

Build failed
Swift Test OS X Platform
Git Sha - e67267549ce4836aa63fb1ce37c35487062b493d

@Catfish-Man
Copy link
Contributor Author

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

swift-ci commented May 3, 2019

Build failed
Swift Test Linux Platform
Git Sha - e67267549ce4836aa63fb1ce37c35487062b493d

@swift-ci
Copy link
Contributor

swift-ci commented May 3, 2019

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
ObjectiveCBridgeStringIsEqualAllSwift 29 32 +10.3% 0.91x (?)

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
ObjectiveCBridgeStringIsEqualAllSwift 29 32 +10.3% 0.91x (?)

Performance: -Onone

TEST OLD NEW DELTA RATIO
Improvement
ObjectiveCBridgeStubNSDataAppend 1960 1800 -8.2% 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 mini
  Model Identifier: Macmini8,1
  Processor Name: 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

@Catfish-Man
Copy link
Contributor Author

That's very suspicious. The case that should have improved is maybe not covered by the benchmarks, and the case that claims to have maybe regressed is a) a very very low workload test, and b) takes a branch just before all the changed code.

I'm still voting no actual change there.

@Catfish-Man
Copy link
Contributor Author

(the thing that will improve is when the Swift string is non-ascii and the NSString is ascii, we won't do all the work to build breadcrumbs)

@Catfish-Man Catfish-Man merged commit 1192b91 into swiftlang:master May 4, 2019
@milseman
Copy link
Member

@Catfish-Man did this get cherry-picked to 5.1?

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.

5 participants