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

fix(benchmark): clear BenchmarkResult.samples array to reduce memory usage #6541

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Sep 21, 2024

Description

I think we should clear BenchmarkResult.samples by default on test runner side. I added benchmark.includeSamples option which allows returning samples, but it's disabled by default.

The fix is verified with this reproduction https://github.com/hi-ogawa/reproductions/tree/main/vitest-6539-bench-heap-oom

Plot of "used_heap_size"

image

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Sep 21, 2024

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 637fe11
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/66ee57a21ac8230008e1635d
😎 Deploy Preview https://deploy-preview-6541--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@hi-ogawa hi-ogawa changed the title fix(benchmark): deal with a huge BenchmarkResult.samples array fix(benchmark): clear BenchmarkResult.samples array to reduce memory usage Sep 21, 2024
@hi-ogawa hi-ogawa marked this pull request as ready for review September 21, 2024 06:04
Copy link
Member

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

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

Would be great to add test case for this in https://github.com/vitest-tests/ and include it in Ecosystem CI. We already have some similar cases there. This one could be benchmark-large.

For example the coverage-large is there to verify that we don't run into similar OOM crash when coverage results of large project are collected. We used to store them in memory - #4603.

The reporters-large is there to verify that Vitest doesn't get completely stuck when there's a lot of reporting to do: #4710.

packages/vitest/src/node/types/benchmark.ts Outdated Show resolved Hide resolved
@@ -24,6 +24,7 @@ export const benchmarkConfigDefaults: Required<
exclude: defaultExclude,
includeSource: [],
reporters: ['default'],
includeSamples: false,
Copy link
Member

Choose a reason for hiding this comment

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

Is this not breaking change? Though benchmarking is experimental feature 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, this is a breaking change. We could start from default true, but I'm hoping that people haven't really needed to have raw samples. For example, since my last PR #5398. benchmark outputJson already omits raw samples.

Co-authored-by: Ari Perkkiö <[email protected]>
Copy link
Contributor Author

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

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

Would be great to add test case for this in https://github.com/vitest-tests/ and include it in Ecosystem CI. We already have some similar cases there. This one could be benchmark-large.

Sounds good! I'll prepare one.

@@ -24,6 +24,7 @@ export const benchmarkConfigDefaults: Required<
exclude: defaultExclude,
includeSource: [],
reporters: ['default'],
includeSamples: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, this is a breaking change. We could start from default true, but I'm hoping that people haven't really needed to have raw samples. For example, since my last PR #5398. benchmark outputJson already omits raw samples.

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.

Vitest has too much memory usage in the face of a large number of benches
2 participants