Skip to content

Add performance measurement test with instructions count #1863

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

kimdv
Copy link
Contributor

@kimdv kimdv commented Jun 28, 2023

As we talked about, it would be nice to have performance tests as part of the CI.

I did dig a bit into XCTCPUMetric.
But I didn't find a nice way to add baselines.

So I tried to make my own measure method so we easily could start adding them in the code

  • Run CI 3 times

@kimdv kimdv requested a review from ahoppen as a code owner June 28, 2023 19:29
@kimdv kimdv force-pushed the kimdv/add-baseline-for-performance-tests branch from e065080 to c3eb411 Compare June 28, 2023 19:37
@ahoppen
Copy link
Member

ahoppen commented Jul 6, 2023

But I didn't find a nice way to add baselines.

AFAIK that’s a known issue that we can’t define baselines when running XCTest using swift test, so we need to define our own, like you did. I have one suggestion though: Define the baselines in a JSON file. By default that JSON file could be Tests/PerformanceTest/baselines.json and we can add the baseline to .gitignore so that everybody can define their own baselines locally. You could then be able to override the baseline using an environment variable and CI would have Tests/PerformanceTest/ci-baselines.json. If the key doesn’t exist in the baseline, the test would fail to make sure we don’t add new performance tests without adding a baseline to ci-baselines.json.

The baseline file could then look as follows:

{
  "testNativeParsingPerformance": 5850081534,
  ...
}

and measureInstructions could infer the test case name from the test function as follows:

func measureInstructions(_ baselineName: StaticString = #function)

@kimdv kimdv force-pushed the kimdv/add-baseline-for-performance-tests branch 3 times, most recently from c7365a5 to ba3e70e Compare July 8, 2023 18:19
@kimdv
Copy link
Contributor Author

kimdv commented Jul 8, 2023

@ahoppen did you think of something like this?

I'm not sure I understand this

You could then be able to override the baseline using an environment variable ...

@kimdv
Copy link
Contributor Author

kimdv commented Jul 8, 2023

@swift-ci please test

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Very nice.

One thought that just crossed my mind: I think it’s a little bit frustrating if all performance tests fail if no baseline file is provided because this means that if you check out the repo and run tests initially, you’ll see test failures. Because of this, what do you think about changing it so that if PerformanceTest/baselines.json doesn’t exist, all performance tests pass. Once you do care about performance, you’ll create a baselines.json and all performance tests for which you don’t have baselines will start failing, which might make sense.

@kimdv kimdv force-pushed the kimdv/add-baseline-for-performance-tests branch 2 times, most recently from 531088a to 7ebe7f3 Compare July 18, 2023 22:57
@kimdv
Copy link
Contributor Author

kimdv commented Jul 18, 2023

@swift-ci please test

@kimdv kimdv force-pushed the kimdv/add-baseline-for-performance-tests branch from 7ebe7f3 to 2d0a54f Compare July 19, 2023 09:10
@kimdv
Copy link
Contributor Author

kimdv commented Jul 19, 2023

@swift-ci please test

@kimdv kimdv force-pushed the kimdv/add-baseline-for-performance-tests branch from 2d0a54f to 115d33a Compare July 19, 2023 11:30
@kimdv
Copy link
Contributor Author

kimdv commented Jul 19, 2023

@swift-ci please test

@kimdv kimdv force-pushed the kimdv/add-baseline-for-performance-tests branch from 115d33a to be475f6 Compare July 19, 2023 16:28
@kimdv
Copy link
Contributor Author

kimdv commented Jul 19, 2023

@swift-ci please test

@kimdv kimdv requested a review from ahoppen July 19, 2023 16:29
@kimdv kimdv force-pushed the kimdv/add-baseline-for-performance-tests branch from be475f6 to 7187539 Compare July 19, 2023 19:59
@kimdv
Copy link
Contributor Author

kimdv commented Jul 19, 2023

@swift-ci please test

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Nice 🤩

@kimdv kimdv force-pushed the kimdv/add-baseline-for-performance-tests branch 2 times, most recently from a318c95 to 3ff99b9 Compare July 20, 2023 09:48
@kimdv
Copy link
Contributor Author

kimdv commented Jul 20, 2023

@swift-ci please test

Baseline

{
   "testNativeParsingPerformance": 311011168,
   "testClassifierPerformance": 2624475912,
   "testEmptyVisitorPerformance": 48502831,
   "testEmptyRewriterPerformance": 54438776,
   "testEmptyAnyVisitorPerformance": 49123765
}

Failed
XCTAssertTrue failed - Number of instructions '307024328'
is not within range 309456112-312566223

1.29017% difference

@kimdv
Copy link
Contributor Author

kimdv commented Jul 20, 2023

@swift-ci please test windows

@kimdv kimdv force-pushed the kimdv/add-baseline-for-performance-tests branch from 3ff99b9 to a5d3c42 Compare July 20, 2023 14:02
@kimdv
Copy link
Contributor Author

kimdv commented Jul 20, 2023

@swift-ci please test

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Looks like we need to increase the allowed deviation to 1%.

@kimdv kimdv force-pushed the kimdv/add-baseline-for-performance-tests branch 4 times, most recently from ee0f2ae to a185b56 Compare July 20, 2023 17:13
@kimdv
Copy link
Contributor Author

kimdv commented Jul 20, 2023

@swift-ci please test

@ahoppen
Copy link
Member

ahoppen commented Jul 20, 2023

Oh, we should only specify the baseline if we are running on macOS. getInstructionCount doesn’t work on Linux and also, even if it did, we would have different performance counters. You can check if we’re running on macOS using

if platform.system() == "Darwin":

@kimdv kimdv force-pushed the kimdv/add-baseline-for-performance-tests branch from a185b56 to b07bcdb Compare July 21, 2023 08:31
@kimdv
Copy link
Contributor Author

kimdv commented Jul 21, 2023

@swift-ci please test

@ahoppen
Copy link
Member

ahoppen commented Jul 21, 2023

2/3

@swift-ci please test

@kimdv
Copy link
Contributor Author

kimdv commented Jul 21, 2023

3/3

@swift-ci please test

@kimdv kimdv merged commit aa49fec into swiftlang:main Jul 22, 2023
@kimdv kimdv deleted the kimdv/add-baseline-for-performance-tests branch July 22, 2023 07:59
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.

2 participants