Skip to content

Audit parameterized selectors with single-entry caches across app/selectors (51 hits, 14 files) #31494

Description

@MajorLift

Performance audit finding · Severity: Medium (batch) · Effort: Large · Fix risk: Simple per instance · Test safety net: Partial
Owner: per-file CODEOWNERS
Scope: app/selectors/ (51 hits, 14 files)

What is this about?

Parameterized selectors ((_state, arg) => arg input pattern) built with createSelector have a single-entry cache: calls with alternating arguments from different components bust the cache on every call, so the selector recomputes per call site per render despite being "memoized". Sweep results on main (b3e7eb88), hits per file:

Detection recipe: grep -rn "(_state\|(_," app/selectors --include="*.ts"

Technical Details

Per instance, triage in this order: (1) lookup-map selector — memoize one keyed index, consumers key into it (preferred; removes per-arg caching entirely); (2) factory selector instantiated per call site with useMemo; (3) lruMemoize with maxSize (last resort). Instances called from a single call site with a stable argument are fine — close them as no-op with a note.

Acceptance Criteria

  • Each file's hits triaged: fixed (with reference-stability test) or explicitly waived (single stable call site).
  • No parameterized selector consumed per-row in a list retains a single-entry cache.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    To be fixed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions