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

perf(dot-renderer): speed up getTests #3923

Merged
merged 1 commit into from Aug 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/runner/src/utils/tasks.ts
Expand Up @@ -6,7 +6,22 @@ function isAtomTest(s: Task): s is Test | TaskCustom {
}

export function getTests(suite: Arrayable<Task>): (Test | TaskCustom)[] {
return toArray(suite).flatMap(s => isAtomTest(s) ? [s] : s.tasks.flatMap(c => isAtomTest(c) ? [c] : getTests(c)))
const tests: (Test | TaskCustom)[] = []
Copy link
Member

Choose a reason for hiding this comment

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

Interestingly this would affect the performance so much. To get a bit more juice out of it, maybe we could have a second argument to pass into the recusive and avoiding creating a new array on every call?

like

export function getTests(suite: Arrayable<Task>, tests: (Test | TaskCustom)[] = []): (Test | TaskCustom)[] {

	// ...
  getTests(task, tests)
  // ...

  return tests
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't seem to provide a noticeable improvement consistently, so probably fine to keep it as it is?

const suite_arr = toArray(suite)
for (const s of suite_arr) {
if (isAtomTest(s)) {
tests.push(s)
}
else {
for (const task of s.tasks) {
if (isAtomTest(task))
tests.push(task)
else
tests.push(...getTests(task))
}
}
}
return tests
}

export function getTasks(tasks: Arrayable<Task> = []): Task[] {
Expand Down