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

Sm/perf-gains #726

Merged
merged 6 commits into from
Jul 11, 2023
Merged

Sm/perf-gains #726

merged 6 commits into from
Jul 11, 2023

Conversation

mshanemc
Copy link
Member

@mshanemc mshanemc commented Jul 10, 2023

rewrite of Parse and Validate (flags only, not args)

this branch:
$ ts-node test/perf/parser.perf.ts
simple x 131,268 ops/sec ±1.15% (79 runs sampled)
multiple async flags that take time x 9.90 ops/sec ±0.14% (50 runs sampled)
flagstravaganza x 7,425 ops/sec ±2.10% (83 runs sampled)

main
$ ts-node test/perf/parser.perf.ts
simple x 103,392 ops/sec ±0.91% (77 runs sampled)
multiple async flags that take time x 4.96 ops/sec ±0.13% (28 runs sampled)
multiple async flags that take time x 5,451 ops/sec ±2.09% (79 runs sampled)

lots of refactoring was needed to enable parallelization, but the main goal is to run flags' async parse methods in parallel.

The code could be a lot cleaner if we could make the assumption that this.context on Parser is not mutating.

That middle perf test multiple async flags that take time is meant to model something that's got some delay on it (ex, various local fs operations like sf's Org flag)


const failed = results.filter(r => r.status === 'failed')
if (failed.length > 0) throw new FailedFlagValidationError({parse, failed})
}

async function resolveFlags(flags: FlagRelationship[]): Promise<Record<string, unknown>> {
if (cachedResolvedFlags) return cachedResolvedFlags
Copy link
Member Author

@mshanemc mshanemc Jul 10, 2023

Choose a reason for hiding this comment

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

this could be called a lot of times, so I memoized it

const flags = relationship.flags ?? []
const results = []
function validateRelationships(name: string, flag: CompletableFlag<any>): Promise<Validation>[] {
return ((flag.relationships ?? []).map(relationship => {
Copy link
Member Author

Choose a reason for hiding this comment

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

returns an array of promises. No need to await them--someone else can do that later.

@mshanemc mshanemc added the enhancement New feature or request label Jul 10, 2023
@git2gus
Copy link

git2gus bot commented Jul 10, 2023

This issue has been linked to a new work item: W-13734277

} else {
flags[token.flag] = true
try {
if (flag.type === 'boolean') {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do this check if it's a boolean, looks like it's the same call on L223 as 226

Copy link
Contributor

Choose a reason for hiding this comment

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

pulled it down and looked at it... that's weird though

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah--the oclif types are a bit confused.

@@ -81,15 +87,11 @@ export async function validate(parse: {
return result ? [flag.name, parse.output.flags[flag.name]] : null
})
const resolved = await Promise.all(promises)
return Object.fromEntries(resolved.filter(r => r !== null) as [string, unknown][])
cachedResolvedFlags = Object.fromEntries(resolved.filter(r => r !== null) as [string, unknown][])
Copy link
Contributor

Choose a reason for hiding this comment

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

return Object.fromEntries...?

Copy link
Member Author

Choose a reason for hiding this comment

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

this could be called a lot of times, so I memoized it

src/parser/parse.ts Outdated Show resolved Hide resolved
@WillieRuemmele
Copy link
Contributor

it is faster 🏎️ 🏁

 ➜  ts-node test/perf/parser.perf.ts
simple x 267,234 ops/sec ±5.49% (85 runs sampled)
multiple async flags that take time x 9.86 ops/sec ±0.23% (50 runs sampled)
flagstravaganza x 14,873 ops/sec ±2.47% (86 runs sampled)
➜  core git:(sm/perf-gains) 
 ➜  ts-node test/perf/parser.perf.ts
simple x 266,510 ops/sec ±5.54% (85 runs sampled)
multiple async flags that take time x 9.85 ops/sec ±0.11% (49 runs sampled)
flagstravaganza x 14,844 ops/sec ±2.37% (85 runs sampled)
➜  core git:(sm/perf-gains) 
 ➜  gco main src                        
Updated 3 paths from 569eb75
➜  core git:(sm/perf-gains) ✗ 
 ➜  yb  
yarn run v1.22.19
$ shx rm -rf lib && tsc
✨  Done in 2.42s.
➜  core git:(sm/perf-gains) ✗ 
 ➜  ts-node test/perf/parser.perf.ts
simple x 216,811 ops/sec ±5.08% (85 runs sampled)
multiple async flags that take time x 4.92 ops/sec ±0.11% (28 runs sampled)
flagstravaganza x 12,968 ops/sec ±2.84% (87 runs sampled)
➜  core git:(sm/perf-gains) ✗ 
 ➜  ts-node test/perf/parser.perf.ts
simple x 213,781 ops/sec ±5.69% (84 runs sampled)
multiple async flags that take time x 4.92 ops/sec ±0.12% (28 runs sampled)
flagstravaganza x 12,806 ops/sec ±2.86% (86 runs sampled)

@WillieRuemmele
Copy link
Contributor

QA Notes


✅ : validated with NUTs
✅ : in PRM with this built and linked required flag

 ➜  ../../oss/plugin-release-management/bin/dev github:check:closed                                                   
Error (1): The following error occurred:
  Missing required flag github-token

✅ : read flag value

 ➜  ../../oss/plugin-release-management/bin/dev github:check:closed --github-token abc
Error (1): Bad credentials

✅ : required flag validated

 ➜  ../../oss/plugin-release-management/bin/dev github:check:closed                                                   
Error (1): The following error occurred:
  Missing required flag github-token

✅ : read from env

 ➜  GITHUB_TOKEN=abc ../../oss/plugin-release-management/bin/dev github:check:closed
Error (1): Bad credentials

✅ : relationship flags still validated

 ➜  ../../oss/plugin-deploy-retrieve/bin/dev project:deploy:start -d force-app --results-dir abc                      
Error (1): The following error occurred:
  One of the following must be provided when using --results-dir: --coverage-formatters, --junit

@WillieRuemmele WillieRuemmele merged commit c6291de into main Jul 11, 2023
22 checks passed
@WillieRuemmele WillieRuemmele deleted the sm/perf-gains branch July 11, 2023 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants