Skip to content

[benchmark] UnsafeRawBufferPointer._copyContents #38827

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 2 commits into from
Aug 13, 2021

Conversation

glessard
Copy link
Contributor

@glessard glessard commented Aug 10, 2021

Add a benchmark to measure UnsafeRawBufferPointer._copyContents. Prompted by the observation that creating an [UInt8] from an UnsafeRawBufferPointer is slow, while creating a [UInt8] from an UnsafeBufferPointer<UInt8> is much faster. This slowness was reported in https://bugs.swift.org/browse/SR-9604.
The fast path to initialize Array from a Collection ultimately relies on said collection's implementation of _copyContents, therefore we benchmark URBP's implementation.

@glessard
Copy link
Contributor Author

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Performance (x86_64): -O

Regression OLD NEW DELTA RATIO
DictionaryOfAnyHashableStrings_insert 3178 5600 +76.2% 0.57x (?)
Set.isDisjoint.Int50 268 336 +25.4% 0.80x (?)
ObjectiveCBridgeStubFromNSDate 6280 7140 +13.7% 0.88x (?)
DictionaryKeysContainsNative 23 26 +13.0% 0.88x (?)
FlattenListLoop 4242 4771 +12.5% 0.89x (?)
 
Improvement OLD NEW DELTA RATIO
XorLoop 1890 1747 -7.6% 1.08x (?)
ArrayPlusEqualFiveElementCollection 8436 7807 -7.5% 1.08x (?)
ArrayAppendReserved 1480 1370 -7.4% 1.08x (?)
Array2D 7216 6688 -7.3% 1.08x (?)
ArrayPlusEqualSingleElementCollection 1927 1786 -7.3% 1.08x (?)
 
Added MIN MAX MEAN MAX_RSS
FillArrayFromRawBuffer 686 699 693

Code size: -O

Regression OLD NEW DELTA RATIO
BufferFill.o 7268 9211 +26.7% 0.79x

Performance (x86_64): -Osize

Regression OLD NEW DELTA RATIO
FlattenListLoop 3975 5226 +31.5% 0.76x (?)
Array2D 6928 7520 +8.5% 0.92x (?)
XorLoop 1747 1890 +8.2% 0.92x (?)
ArrayPlusEqualFiveElementCollection 7696 8325 +8.2% 0.92x (?)
ArrayAppendReserved 1370 1480 +8.0% 0.93x (?)
ArrayPlusEqualSingleElementCollection 1786 1927 +7.9% 0.93x (?)
RandomShuffleLCG2 416 448 +7.7% 0.93x (?)
ArrayAppend 1580 1700 +7.6% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
ObjectiveCBridgeStubFromNSDate 7400 6320 -14.6% 1.17x (?)
DictionaryKeysContainsNative 30 26 -13.3% 1.15x (?)
FlattenListFlatMap 4335 4011 -7.5% 1.08x (?)
 
Added MIN MAX MEAN MAX_RSS
FillArrayFromRawBuffer 686 735 709

Code size: -Osize

Regression OLD NEW DELTA RATIO
BufferFill.o 8106 9838 +21.4% 0.82x

Performance (x86_64): -Onone

Regression OLD NEW DELTA RATIO
String.data.Empty 75 84 +12.0% 0.89x (?)
 
Added MIN MAX MEAN MAX_RSS
FillArrayFromRawBuffer 915 1252 1027

Code size: -swiftlibs

Benchmark Check Report
⚠️🔤 FillArrayFromRawBuffer name is composed of 5 words.
Split FillArrayFromRawBuffer name into dot-separated groups and variants. See http://bit.ly/BenchmarkNaming
⚠️Ⓜ️ FillArrayFromRawBuffer has very wide range of memory used between independent, repeated measurements.
FillArrayFromRawBuffer mem_pages [i1, i2]: min=[594, 594] 𝚫=0 R=[0, 203]
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

@glessard glessard force-pushed the buffer-benchmarks branch 2 times, most recently from 0a9421d to 2699a85 Compare August 10, 2021 23:36
@glessard glessard changed the title [benchmark] Array creation from an UnsafeRawBufferPointer [benchmark] UnsafeRawBufferPointer._copyContents Aug 10, 2021
@glessard glessard force-pushed the buffer-benchmarks branch 2 times, most recently from 7315d9c to 0ad5a74 Compare August 11, 2021 00:04
@glessard
Copy link
Contributor Author

@swift-ci please benchmark

@glessard
Copy link
Contributor Author

@swift-ci please smoke test

@swift-ci
Copy link
Contributor

Performance (x86_64): -O

Regression OLD NEW DELTA RATIO
DictionaryOfAnyHashableStrings_insert 2030 3752 +84.8% 0.54x
Set.isDisjoint.Box25 285 397 +39.3% 0.72x (?)
Set.isDisjoint.Int50 202 241 +19.3% 0.84x (?)
 
Added MIN MAX MEAN MAX_RSS
RawBuffer.copyContents 730 742 737

Code size: -O

Regression OLD NEW DELTA RATIO
BufferFill.o 7268 9467 +30.3% 0.77x

Performance (x86_64): -Osize

Added MIN MAX MEAN MAX_RSS
RawBuffer.copyContents 543 559 552

Code size: -Osize

Regression OLD NEW DELTA RATIO
BufferFill.o 8106 10183 +25.6% 0.80x

Performance (x86_64): -Onone

Added MIN MAX MEAN MAX_RSS
RawBuffer.copyContents 871 889 877

Code size: -swiftlibs

Benchmark Check Report
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

@glessard
Copy link
Contributor Author

@swift-ci please smoke check

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.

🚢

@glessard
Copy link
Contributor Author

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit 65244f0 into swiftlang:main Aug 13, 2021
@glessard glessard deleted the buffer-benchmarks branch August 13, 2021 00: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.

3 participants