Skip to content

perf(expect): avoid redefining matcher state - #11048

Merged
sheremet-va merged 2 commits into
vitest-dev:mainfrom
scttcper:scttcper/expect-state-update
Aug 26, 2026
Merged

perf(expect): avoid redefining matcher state#11048
sheremet-va merged 2 commits into
vitest-dev:mainfrom
scttcper:scttcper/expect-state-update

Conversation

@scttcper

Copy link
Copy Markdown
Contributor

Codex assisted with this PR; I reviewed the changes and benchmark results.

Every expect(value) updates assertionCalls, but setState was redefining every existing state property and writing the same object back to its WeakMap. This applies only the incoming patch descriptors and inserts state into the map only during initialization, while preserving getters such as testPath.

expect(value) Calls/sec Relative
Before 606,431 1.00x
After 2,042,637 3.37x

Measured on Node 26.7.0 with 10 samples of 250,000 calls after a 50,000-call warmup.

Only apply incoming descriptors and initialize the WeakMap entry once.

Co-Authored-By: Codex <noreply@openai.com>
@github-actions github-actions Bot added the maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control label Aug 24, 2026
@github-actions

Copy link
Copy Markdown

Hello @scttcper. Your PR has been labeled maybe automated because it appears to have been fully generated by AI with no human involvement.

To keep your PR open, please follow these steps:

  • Confirm that you are a real human. If you are an automated agent, disclose that
  • Make sure you've read, reviewed and stand behind its content
  • Make sure you've read the full issue along with all of its comments, as well as any linked issues and their comments
  • Make sure it follows our contribution guidelines and uses the correct GitHub template
  • Disclose any AI tools you used (e.g. Claude, Copilot, Codex)

Please, do not generate or format the response with AI. If you do not speak English, reply in your native language or use translation software like Google Translate or Deepl. If the response is generated, the PR will be closed automatically.

These measures help us reduce maintenance burden and keep the team's work efficient. See our AI contributions policy for more context.

@netlify

netlify Bot commented Aug 24, 2026

Copy link
Copy Markdown

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c171ac8
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a8be1afc4b1d200086a6048
😎 Deploy Preview https://deploy-preview-11048--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@scttcper

scttcper commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

i'm a human watching codex/chatgpt profile a few things. found this small change to expect that should hopefully be pretty straight forward and i have reviewed. Very much a microbenchmark but should be small enough change to go with it.

edit: failing test looks like a flake

@scttcper
scttcper marked this pull request as ready for review August 24, 2026 06:19
@sheremet-va sheremet-va removed the maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control label Aug 25, 2026
@sheremet-va
sheremet-va merged commit 58e7130 into vitest-dev:main Aug 26, 2026
29 checks passed
@sheremet-va

Copy link
Copy Markdown
Member

LGTM 👍

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