perf: avoid copying mock history in call-count assertions - #62
Open
exo-egor wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Count-only mock assertions currently rebuild the entire argument history to read its length. Use the underlying mock context's counter through a WeakMap, retaining the existing fallback for Jest-compatible mocks. This makes successful count lookups constant-time and adds no fields to mock objects. The registry lives in its own internal module so the bundler does not mistake mock setup for usage of
expect.A synthetic loop of 5,000 mock calls, each followed by
toHaveBeenCalledTimes, improved from 185–200 ms to 20–21 ms on Node 22.22.0 / macOS (about 9× for that loop). These are the medians of seven samples after three warm-up loops, in two separate processes per revision. Whole-suite speedup has not been measured.Validation:
FORCE_COLOR=1for the existing color-dependent snapshots).@exodus/import/no-extraneous-dependencieserror intests/jest/setup.cjs:9, reproduced on untouched upstreammain.Microbenchmark reproduction
Run this from either checkout with
EXODUS_TEST_ENGINE=node:test node --input-type=module: