Skip to content

Comments

perf: reduce redundant property access in getDirtyFields#13146

Merged
bluebill1049 merged 1 commit intoreact-hook-form:masterfrom
kimtaejin3:perf/reduce-property-access-getDirtyFields
Nov 14, 2025
Merged

perf: reduce redundant property access in getDirtyFields#13146
bluebill1049 merged 1 commit intoreact-hook-form:masterfrom
kimtaejin3:perf/reduce-property-access-getDirtyFields

Conversation

@kimtaejin3
Copy link
Contributor

Problem

In getDirtyFields.ts, data[key] and formValues[key] are accessed multiple times per iteration, causing unnecessary property lookup overhead.

Solution

Cache property values in variables to eliminate redundant lookups.

Changes

  • Added const value = data[key] in markFieldsDirty function
  • Added const value = data[key] in getDirtyFields main loop
  • Added const formValue = formValues[key] in else block

Performance Results

Benchmarked 5 times with consistent results:

Form Size Before After Improvement
Medium (50 fields) 19.58ms 17.44ms 11.0% faster
Large (100+ fields) 21.48ms 19.65ms 8.5% faster

Average improvement: ~10%

Testing

  • ✅ All 13 tests pass
  • ✅ Type checking passes
  • ✅ Zero logic changes (pure performance optimization)

Cache data[key] and formValues[key] in variables to eliminate
repeated lookups.

Performance improvement: ~10% faster across different form sizes.
- Medium forms (50 fields): 19.58ms → 17.44ms (11.0% faster)
- Large forms (100+ fields): 21.48ms → 19.65ms (8.5% faster)

All tests pass (13/13).
@kimtaejin3 kimtaejin3 changed the title ⚡ perf: reduce redundant property access in getDirtyFields perf: reduce redundant property access in getDirtyFields Nov 14, 2025
@bluebill1049
Copy link
Member

wow

@bluebill1049 bluebill1049 merged commit d13be6a into react-hook-form:master Nov 14, 2025
6 checks passed
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