Skip to content

Benchmarks for dropLast and suffix #7420

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

therealbnut
Copy link
Contributor

@therealbnut therealbnut commented Feb 13, 2017

Adds benchmarks testing dropLast and suffix, so we have a baseline for optimisations and improvements.

Note: the various arrays seemed to be in alphabetical order, with a few exceptions. I sorted those where it seemed like it was meant to be. I'm happy to revert that.

This is in order to facilitate #7250

It also will allow us to determine the efficiency of the non-specialised AnySequence implementations. For example:

 54 DropLastAnySequence             3   31460   31927    31695      0      31695    4603904
 55 DropLastCountableRange          3     800     809      804      0        804    4575232
 56 DropLastSequence                3   67560   68419    68100      0      68100    4934315

Ideally DropLastAnySequence would perform similarly to DropLastCountableRange (as, in this case, it wraps a RandomAccessCollection and could find the dropped range in constant time). Likewise for SuffixCountableRange.

Helps benchmark SR-413.

@therealbnut
Copy link
Contributor Author

CC @dabrahams - as discussed in #7250

@therealbnut therealbnut force-pushed the therealbnut-droplast-suffix-benchmarks branch from 263d28c to 4ab188d Compare February 13, 2017 09:52
@therealbnut therealbnut force-pushed the therealbnut-droplast-suffix-benchmarks branch from 4ab188d to 4a55f70 Compare February 13, 2017 10:50
@airspeedswift airspeedswift self-requested a review February 13, 2017 16:42
@airspeedswift
Copy link
Member

The AnySequence perf's pretty disappointing, it's definitely dispatching to the underlying type's implementation so maybe it's specialization that's failing.

Other than that, these look good. Would you mind adding one for Array too?

swiftix added a commit to swiftix/swift that referenced this pull request Feb 22, 2017
… remove these instructions

Discovered this missing peephole while looking at the performance of swiftlang#7420
@therealbnut
Copy link
Contributor Author

therealbnut commented Feb 25, 2017

@airspeedswift added array benchmarks in c6dc0b0

 DropLastAnySequence             3   33643   37585    35984      0      35984    4606635
+DropLastArray                   3    1114    1215     1148      0       1148    4609365
 DropLastCountableRange          3     774     783      779      0        779    4517888
 DropLastSequence                3   65900   66555    66242      0      66242    4722688

and

 SuffixAnySequence               3   36442   38835    37366      0      37366    4651691
+SuffixArray                     3    1196    1214     1204      0       1204    4614827
 SuffixCountableRange            3     832     864      851      0        851    4573867
 SuffixSequence                  3   61049   61647    61296      0      61296    4728149

Sorry for the delay!

@airspeedswift
Copy link
Member

@swift-ci Please smoke test

@airspeedswift
Copy link
Member

@swift-ci Please benchmark

@therealbnut
Copy link
Contributor Author

thanks :)

@swift-ci
Copy link
Contributor

Build comment file:

Optimized (O)


@therealbnut therealbnut force-pushed the therealbnut-droplast-suffix-benchmarks branch from cfcf6c2 to 2c6a30f Compare March 5, 2017 00:56
@therealbnut therealbnut force-pushed the therealbnut-droplast-suffix-benchmarks branch from 2c6a30f to 34d7a4b Compare March 5, 2017 00:57
@therealbnut
Copy link
Contributor Author

@airspeedswift just merged master and fixed conflicts, I think I've addressed all your feedback, was this everything? :)

@lplarson
Copy link
Contributor

lplarson commented Mar 8, 2017

@swift-ci benchmark

1 similar comment
@lplarson
Copy link
Contributor

lplarson commented Mar 8, 2017

@swift-ci benchmark

@lplarson
Copy link
Contributor

lplarson commented Mar 8, 2017

@swift-ci smoke test

@swift-ci
Copy link
Contributor

swift-ci commented Mar 8, 2017

Build comment file:

Build failed before running benchmark.


@lplarson
Copy link
Contributor

lplarson commented Mar 8, 2017

I'll merge this once we get a clean benchmark run. Blocked on #7979.

@lplarson
Copy link
Contributor

@swift-ci benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Optimized (O)


@therealbnut
Copy link
Contributor Author

Merged master, this should include the #7979 fix now, thanks @lplarson

@CodaFi
Copy link
Contributor

CodaFi commented Mar 11, 2017

(Drive-by benchmarking; don't mind me)

@swift-ci benchmark

(Benchmark happening here) // @shahmishal

@swift-ci
Copy link
Contributor

!!! Couldn't read commit file !!!

@therealbnut
Copy link
Contributor Author

therealbnut commented Mar 12, 2017

@CodaFi I think there was a problem with the CI system on your drive-by benchmark, you may need to re-run it

Slave went offline during the build

@shahmishal
Copy link
Member

@swift-ci benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Optimized (O)


@lplarson
Copy link
Contributor

@swift-ci smoke test and merge

1 similar comment
@lplarson
Copy link
Contributor

@swift-ci smoke test and merge

@swift-ci swift-ci merged commit b156cbb into swiftlang:master Mar 14, 2017
@gottesmm
Copy link
Contributor

@lplarson Next time can we do a rebase so we don't have merges in the commit stream?

@therealbnut
Copy link
Contributor Author

therealbnut commented Mar 14, 2017

@gottesmm You can change GitHub settings to prevent merge commits, squash PRs by default, make master ff-only, and require CI. The squash removes any merge commits.

@therealbnut
Copy link
Contributor Author

I think these settings would work well given the current workflow:

https://github.com/apple/swift/settings
screen shot 2017-03-15 at 8 58 25 am

https://github.com/apple/swift/settings/branches/master
screen shot 2017-03-15 at 9 00 56 am

@therealbnut
Copy link
Contributor Author

therealbnut commented Mar 14, 2017

It makes many of the same restrictions if you're pushing using git from the terminal

@therealbnut
Copy link
Contributor Author

Thank you @airspeedswift for your review and @lplarson for your persistence in getting it through CI and merged 💖

@therealbnut therealbnut deleted the therealbnut-droplast-suffix-benchmarks branch March 14, 2017 22:09
@gottesmm
Copy link
Contributor

gottesmm commented Mar 15, 2017 via email

@palimondo
Copy link
Contributor

palimondo commented Mar 26, 2017

@therealbnut said in initial comment:

Ideally DropLastAnySequence would perform similarly to DropLastCountableRange

That is not possible. The way the test is written, MySequence wraps the CountableRange without forwarding to its suffix implementation - thereby explicitly defaulting to the implementation on Sequence. The issue reported in SR-413 was fixed a year ago (see the issue for details). cc @airspeedswift

@therealbnut
Copy link
Contributor Author

@palimondo: Note, my comment was for DropLastAnySequence (which uses AnySequence) not DropLastSequence (which uses MySequence).

As you can see in the benchmarks run here, it is not fixed in February this year:

SuffixAnySequence               3   36442   38835    37366      0      37366    4651691
SuffixArray                     3    1196    1214     1204      0       1204    4614827

@therealbnut
Copy link
Contributor Author

The test intentionally does not forward to Array's suffix implementation in order to call the unspecialised defaulted suffix.

  • DropLastSequence benchmark tests the performance of the default implementation on Sequence
  • DropLastCountableRange benchmark tests the performance of the specialised implementation on CountableRange
  • DropLastAnySequence benchmark tests the performance of AnySequence which will fall somewhere around DropLastSequence at the moment, but ideally it would use CountableRange's specialisation and perform similarly. To do this it needs generic magic that Swift doesn't have yet afaik.

Until AnySequence calls through to the specialised implementation SR-413 is not considered to be fixed.

@dabrahams
Copy link
Contributor

I've done some work in the unicode-rethink branch to simplify forwarding collection APIs and to ensure that all customization points actually get forwarded: https://github.com/apple/swift/blob/unicode-rethink/stdlib/public/core/ForwardingWrapper.swift.gyb

Also, I've been building a new suite of collection wrappers for unicode support using techniques that could greatly benefit AnyCollection et al. by avoiding the need for a dynamically-allocated box in many cases: https://github.com/apple/swift/blob/unicode-rethink/stdlib/public/core/AnyUnicode.swift.gyb#L418

On that basis, I would not invest too much energy in tuning the performance of the existing implementations.

@therealbnut
Copy link
Contributor Author

Sounds great!

@palimondo
Copy link
Contributor

@therealbnut AnySequence does call through to the specialized implementation on the underlying collection. The performance issue you are seeing is due to iterating over elements through the _IteratorBox using witness table of the generic protocol implementation.

Coincidentally the remaining number of elements in the suffix were just so that it gave similar timing as default implementation on the Sequence. I’ve marked SR-413 as Resolved:Done and opened SR-4499 to track the underlying performance issue in existential collections.

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.

9 participants