perf(createSelector): stop allocating dev-check bookkeeping on every call - #773
Open
veksa wants to merge 1 commit into
Open
perf(createSelector): stop allocating dev-check bookkeeping on every call#773veksa wants to merge 1 commit into
veksa wants to merge 1 commit into
Conversation
✅ Deploy Preview for reselect-docs canceled.
|
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
Contributor
|
Nice! Will follow up on these as soon as I have some time. Thanks! |
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.
The dev-mode checks live inside the hot path, and
getDevModeChecksExecutionInfobuilds four objects — a spread, a wrapper, and one per check — every time a selector recomputes its dependencies. Both checks default to'once', so from the second recomputation onwards all four are allocated, read for two booleans, and thrown away.This resolves the two frequencies in place and calls the check functions directly.
getDevModeChecksExecutionInfohas no callers left, so it goes; the publicDevModeChecksExecutionInfotype stays. Production is unaffected — the whole change sits inside theNODE_ENV !== 'production'guard.One thing worth a look in review: I used
hasOwnPropertyrather than??. The spread this replaces meansdevModeChecks: { identityFunctionCheck: undefined }silences the check — it's a present key overriding the default with a frequency that's neither'once'nor'always'— where??would fall back to the global setting and turn it back on. That edge wasn't covered, so there's a test for it now, and it does fail with??. The common case has no overrides and reads the global directly, nohasOwnPropertycall at all.Measured with the harness from #770, dev mode (
yarn bench:hot-path:dev), paired againstmasterin one process, ns/call:(state, props)(state, props)(state, props)argsMemoize: lruMemoize(state)Dev mode was costing 20–27% over production on the parametric cases; it's now roughly 12–20%. The last two rows are selectors called with the state alone — they hit the argument cache, so they don't recompute dependencies and there's nothing here to skip. Recomputation counts are identical throughout.