Skip to content

Commit

Permalink
Merge branch 'sm/perf-metrics' into sm/new-logger
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jun 28, 2023
2 parents 7e9e725 + d62da01 commit 18608f4
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 3 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/perf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# runs some very-large-repo tests (for windows filesystem limits) and commits perf results for comparison
name: perf-tests
on:
push:
branches-ignore: [main]
workflow_dispatch:

# linux will finish ahead of windows, but prevent other branches/commits from hitting simultaneously
# since we're pushing git commits and there would be conflicts
concurrency: perf-test

jobs:
perf-tests:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
cache: yarn
- run: yarn install
- name: Download previous benchmark data
uses: actions/cache@v3
with:
path: ./cache
key: ${{ runner.os }}-benchmark
- run: npm run test:perf | tee test/perf/output.txt

# Run `github-action-benchmark` action
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@5bbce78ef18edf5b96cb2d23e8d240b485f9dc4a
with:
name: Logger Benchmarks - ${{ matrix.os }}
tool: 'benchmarkjs'
output-file-path: test/perf/output.txt
comment-on-alert: true
fail-on-alert: true
# Push and deploy GitHub pages branch automatically
# this has a bug where it creates duplicate commits when summary-always and aut-push are both true
# summary-always: true
comment-always: true
benchmark-data-dir-path: perf-${{ runner.os}}
auto-push: true
github-token: ${{ secrets.SVC_CLI_BOT_GITHUB_TOKEN }}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,13 @@ In your plugin or library,
}

```

## Performance Testing

There are some benchmark.js checks to get a baseline for Logger performance.
https://forcedotcom.github.io/sfdx-core/perf-Linux
https://forcedotcom.github.io/sfdx-core/perf-Windows

You can add more test cases in test/perf/logger/main.js

If you add tests for new parts of sfdx-core outside of Logger, add new test Suites and create new jobs in the GHA `perf.yml`
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"prepack": "sf-prepack",
"prepare": "sf-install",
"test": "wireit",
"test:only": "wireit"
"test:only": "wireit",
"test:perf": "ts-node test/perf/logger/main.test.ts"
},
"keywords": [
"force",
Expand Down Expand Up @@ -61,13 +62,15 @@
"@salesforce/dev-scripts": "^5.4.2",
"@salesforce/prettier-config": "^0.0.3",
"@salesforce/ts-sinon": "^1.4.8",
"@types/benchmark": "^2.1.2",
"@types/chai-string": "^1.4.2",
"@types/jsonwebtoken": "9.0.2",
"@types/lodash": "^4.14.195",
"@types/proper-lockfile": "^4.1.2",
"@types/shelljs": "0.8.12",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.11",
"benchmark": "^2.1.4",
"chai": "^4.3.7",
"chai-string": "^1.5.0",
"eslint": "^8.43.0",
Expand Down
40 changes: 40 additions & 0 deletions test/perf/logger/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { Suite } from 'benchmark';
import { Logger } from '../../../src/exported';

const suite = new Suite();

const logger = new Logger('Benchmarks');

// add tests
suite
.add('Child logger creation', () => {
// eslint-disable-next-line @typescript-eslint/prefer-includes
Logger.childFromRoot('benchmarkChild');
})
.add('Logging a string on root logger', () => {
logger.debug('this is a string');
})
.add('Logging an object on root logger', () => {
logger.debug({ foo: 1, bar: 2, baz: 3 });
})
.add('Logging an object with a message on root logger', () => {
logger.debug({ foo: 1, bar: 2, baz: 3 }, 'this is a message');
})
.add('Logging an object with a redacted prop on root logger', () => {
logger.debug({ foo: 1, bar: 2, accessToken: '00D' });
})
.add('Logging a nested 3-level object on root logger', () => {
logger.debug({ foo: 1, bar: 2, baz: { foo: 1, bar: 2, baz: { foo: 1, bar: 2, baz: 3 } } });
})
// add listeners
.on('cycle', (event: any) => {
// eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-member-access
console.log(String(event.target));
})
.run({ async: true });
2 changes: 1 addition & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "@salesforce/dev-config/tsconfig-test-strict",
"include": ["unit/**/*.ts"],
"include": ["unit/**/*.ts", "perf/**/*.ts"],
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true,
Expand Down
20 changes: 19 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,11 @@
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.3.tgz#472eaab5f15c1ffdd7f8628bd4c4f753995ec79e"
integrity sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==

"@types/benchmark@^2.1.2":
version "2.1.2"
resolved "https://registry.yarnpkg.com/@types/benchmark/-/benchmark-2.1.2.tgz#b7838408c93dc08ceb4e6e13147dbfbe6a151f82"
integrity sha512-EDKtLYNMKrig22jEvhXq8TBFyFgVNSPmDF2b9UzJ7+eylPqdZVo17PCUMkn1jP6/1A/0u78VqYC6VrX6b8pDWA==

"@types/chai-string@^1.4.2":
version "1.4.2"
resolved "https://registry.yarnpkg.com/@types/chai-string/-/chai-string-1.4.2.tgz#0f116504a666b6c6a3c42becf86634316c9a19ac"
Expand Down Expand Up @@ -1172,6 +1177,14 @@ base64url@^3.0.1:
resolved "https://registry.yarnpkg.com/base64url/-/base64url-3.0.1.tgz#6399d572e2bc3f90a9a8b22d5dbb0a32d33f788d"
integrity sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A==

benchmark@^2.1.4:
version "2.1.4"
resolved "https://registry.yarnpkg.com/benchmark/-/benchmark-2.1.4.tgz#09f3de31c916425d498cc2ee565a0ebf3c2a5629"
integrity sha512-l9MlfN4M1K/H2fbhfMy3B7vJd6AGKJVQn2h6Sg/Yx+KckoUA7ewS5Vv6TjSq18ooE1kS9hhAlQRH3AkXIh/aOQ==
dependencies:
lodash "^4.17.4"
platform "^1.3.3"

binary-extensions@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
Expand Down Expand Up @@ -3233,7 +3246,7 @@ lodash.upperfirst@^4.3.1:
resolved "https://registry.yarnpkg.com/lodash.upperfirst/-/lodash.upperfirst-4.3.1.tgz#1365edf431480481ef0d1c68957a5ed99d49f7ce"
integrity sha512-sReKOYJIJf74dhJONhU4e0/shzi1trVbSWDOhKYE5XV2O+H7Sb2Dihwuc7xWxVl+DgFPyTqIN3zMfT9cq5iWDg==

lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.21:
lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.21, lodash@^4.17.4:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
Expand Down Expand Up @@ -3885,6 +3898,11 @@ pkg-dir@^4.1.0:
dependencies:
find-up "^4.0.0"

platform@^1.3.3:
version "1.3.6"
resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.6.tgz#48b4ce983164b209c2d45a107adb31f473a6e7a7"
integrity sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==

prelude-ls@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
Expand Down

0 comments on commit 18608f4

Please sign in to comment.