Skip to content
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

Adopt package-benchmark #125

Merged
merged 48 commits into from
Sep 21, 2023
Merged

Adopt package-benchmark #125

merged 48 commits into from
Sep 21, 2023

Conversation

dnadoba
Copy link
Member

@dnadoba dnadoba commented Aug 18, 2023

Motivation

Our current allocation tests are using NIOs allocation counter framework which we clone from swift-nio main. This has served us well for last couple years and there was now better solution. Fast forward to day, we have a new package benchmark plugin from the community that we can use to improve our workflow of writing and running all sorts of benchmarks. It uses standard Packages and can be driven directly from the SwiftPM CLI.

Modifications

  • add a sub Swift Package with that include the benchmarks. We can't add it directly to our root Package.swift because package-benchmark has higher minimum platform version requirements.
  • move benchmarks over from /IntegerationTests as a separate library target
  • add test target that uses XCTest to run the benchmarks so we can easily execute single benchmarks from within Xcode
  • add executable test target that use package-benchmark to drive the execution of the benchmarks
  • add allocation limits under benchmarks/Thresholds/
  • add script dev/update-benchmark-thresholds that executes the benchmarks locally using docker for all supported swift versions and updates the thresholds
  • run benchmarks as part of our test CI for each swift version after our normal test have succeeded
  • delete old integration tests

Results

Allocations tests are more accessible, easier to iterate and include more metrics.

@dnadoba dnadoba added the semver/none No version bump required. label Aug 18, 2023
Copy link
Member

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

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

Overall love it! We should also commit the base lines and let all of this run on the CI. We probably don't want to have the time based metrics run on the CI.

@hassila
Copy link

hassila commented Aug 18, 2023

Overall love it! We should also commit the base lines and let all of this run on the CI. We probably don't want to have the time based metrics run on the CI.

Yeah, time based metrics mostly only works if you have dedicated CI runners for them (that's how we do it), the results are way to flakey in general at least on GitHubs runners. But you might still want to run the metrics on the CI and just set thresholds that allow for any time deviation to be ok, then you have them readily accessible if/when running and checking things manually.

@hassila
Copy link

hassila commented Aug 23, 2023

Just one heads-up for the arc numbers - in case you do other tests that use task groups: swiftlang/swift#64636 (still relevant to check for most tests, just FYI)

@FranzBusch
Copy link
Member

Just one heads-up for the arc numbers - in case you do other tests that use task groups: swiftlang/swift#64636 (still relevant to check for most tests, just FYI)

@ktoso the issue might be more relevant now when we adopt the benchmark plugin

@dnadoba
Copy link
Member Author

dnadoba commented Sep 14, 2023

I'm now quite happy with this PR. I have disabled retain/release deltas as they are currently almost never zero. Likely immortals objects are one reason but this needs more investigation.

async code still seems to be quite flaky in the number of retain/release. We aren't actually doing an async work in the test. I have disabled it for now. Also needs more investigation. Maybe async code will never have a stable retain/release count and this is just expected? cc @ktoso

@Lukasa are you also fine with the state of this PR?

Copy link
Member

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

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

@dnadoba I have one more request. Can we add something to our readme here that links to the benchmark docs for how to get started with the benchmarking? Just a two liner or something like this so people find how to run and debug benchmarks.

@dnadoba
Copy link
Member Author

dnadoba commented Sep 21, 2023

@FranzBusch added a section to the README

README.md Outdated

## Benchmarks

Benchmarks for `swift-certificates` are in a separate Swift Package in the `benchmarks` subfolder of this repository.
Copy link
Member

Choose a reason for hiding this comment

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

Oh I have one more nit: Can we name the folder Benchmarks to be in-line with Sources and Tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

its on purpose not uppercase as it is a separate package and folders of packages are lowercase.

README.md Outdated
Comment on lines 56 to 57
Benchmarks depends on the [`jemalloc`](https://jemalloc.net) memory allocation library, which is used by `package-benchmark` to capture memory allocation statistics.
An installation guide can be found in the [Getting Started article](https://swiftpackageindex.com/ordo-one/package-benchmark/1.11.1/documentation/benchmark/gettingstarted#Installing-Prerequisites-and-Platform-Support) of `package-benchmark`.
Copy link
Member

Choose a reason for hiding this comment

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

This part is very prone to get outdated. Can we just link to the index page of the documentation here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have removed the version number and it will now always pointer to the latest version. I really want to keep the direct link to the Getting Started article. I don't think it is very likely they will rename the Getting Started article. The section name "Installing-Prerequisites-and-Platform-Support" may change but that's fine, the link will still work and point to the top of the getting started page.

README.md Outdated
Comment on lines 63 to 67
Profiling benchmarks in Xcode (or building the benchmarks in release mode) with `jemalloc` is currently not supported and requires disabling `jemalloc`.
Make sure Xcode is closed and then open it from the CLI with the `BENCHMARK_DISABLE_JEMALLOC=true` environment variable set e.g.:
```
BENCHMARK_DISABLE_JEMALLOC=true xed .
```
Copy link
Member

Choose a reason for hiding this comment

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

Do they have this documented as well? I would prefer if we just keep as much out of our docs as possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

No they haven't. I'm fine to remove it if package-benchmark adds it but we can also remove it again in a subsequence PR to unblock more benchmarks that I have in the pipeline. cc @hassila

Copy link

Choose a reason for hiding this comment

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

We can definitely add the comment about how to run in Xcode for profiling etc, np.

Copy link
Member

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for pushing on this.

@@ -12,7 +12,8 @@ services:
test:
image: swift-certificates:22.04-5.7
environment:
- MAX_ALLOCS_ALLOWED_parse_webpki_roots=200050
- SWIFT_VERSION=5.7
- MAX_ALLOCS_ALLOWED_parse_webpki_roots=422050
- MAX_ALLOCS_ALLOWED_tiny_array_cow_append_contents_of=9050
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to drop the MAX_ALLOCS_ALLOWED variables?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, just an oversight. removed them now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/none No version bump required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants