Skip to content

[SDK] Use withContiguousStorageIfAvailable in some overlay methods #22001

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

Closed
wants to merge 1 commit into from

Conversation

karwa
Copy link
Contributor

@karwa karwa commented Jan 19, 2019

No description provided.

@karwa
Copy link
Contributor Author

karwa commented Jan 21, 2019

CC @moiseev @milseman

Now that we have a consistent and public way to access the underlying contiguous storage of generic Sequences, we should use it. For one thing it lets you use slices and unsafe buffers without copying.

@moiseev moiseev requested a review from phausler January 23, 2019 18:27
Copy link
Contributor

@phausler phausler left a comment

Choose a reason for hiding this comment

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

Looks good to me

}
withContiguousStorageIfAvailable(_clip) ??
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor stylistic nitpick. Just discussed it with @milseman and we agreed that it would be more readable if these two lines are reformatted as the following:

withContiguousStorageIfAvailable(_clip)
?? Array(self).withUnsafeBufferPointer(_clip)

This way it is clear that the second line is not a new statement, but instead is a previous expression continued.
What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. Updated.

.map(String._unconditionallyBridgeFromObjectiveC)
}
guard let str = bytes.withContiguousStorageIfAvailable(_makeString) ??
Array(bytes).withUnsafeBufferPointer(_makeString) else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

guard let str = bytes.withContiguousStorageIfAvailable(_makeString)
             ?? Array(bytes).withUnsafeBufferPointer(_makeString) else {
  return nil
}

@milseman
Copy link
Member

That conflict is from #21959. When you resolve it, can you make sure we still form native strings from valid UTF-8 contents? The benchmarks will reflect this improvement as well.

@milseman milseman self-assigned this Jan 24, 2019
@karwa
Copy link
Contributor Author

karwa commented Jan 31, 2019

@milseman Rebased.

@milseman
Copy link
Member

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
UTF8Decode_InitFromBytes_ascii 301 427 +41.9% 0.70x
UTF8Decode_InitFromBytes 247 272 +10.1% 0.91x (?)

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
UTF8Decode_InitFromBytes_ascii 302 424 +40.4% 0.71x
UTF8Decode_InitFromBytes 249 272 +9.2% 0.92x (?)
Improvement
ObjectiveCBridgeStubURLAppendPathRef2 2769 2587 -6.6% 1.07x (?)

Performance: -Onone

TEST OLD NEW DELTA RATIO
Regression
UTF8Decode_InitFromBytes_ascii 298 431 +44.6% 0.69x
UTF8Decode_InitFromBytes 247 273 +10.5% 0.90x (?)
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
--------------

@karwa
Copy link
Contributor Author

karwa commented Jan 31, 2019

This doesn't really show the benefit because those benchmarks use Array, which wouldn't copy even in unspecialised generic code.

Created #22277 to add benchmarks for UBP, URBP. The same should apply to Slice/ArraySlice.

@milseman
Copy link
Member

milseman commented Feb 4, 2019

Ok, do you know why there is a 41% regression when it is an array, though?

@karwa
Copy link
Contributor Author

karwa commented Feb 6, 2019

Not yet, I'll check it out. I've found these benchmarks to be pretty noisy locally.

In any case, I think we could speed it up a teeny bit more by copying to ContiguousArray.

@shahmishal
Copy link
Member

Please update the base branch to main by Oct 5th otherwise the pull request will be closed automatically.

  • How to change the base branch: (Link)
  • More detail about the branch update: (Link)

@shahmishal shahmishal closed this Oct 5, 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.

6 participants