Skip to content

Commit 7e2a134

Browse files
committed
Minor optimization: remove conditional
The conditional in selectDerivedProps is unnecessary. The code behaves identically now but saves about 10% of performance for that portion of the function. See: https://jsperf.com/conditional-vs-not Code left in place but commented in case someone ever wants to add something like it back for "clarity".
1 parent f2ac4cc commit 7e2a134

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/components/connectAdvanced.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ export default function connectAdvanced(
151151

152152
const nextProps = sourceSelector(state, props)
153153

154-
if (lastDerivedProps === nextProps) {
155-
return lastDerivedProps
156-
}
154+
// Conditional test costs more than just assigning each time
155+
// See: https://jsperf.com/conditional-vs-not
156+
// if (lastDerivedProps === nextProps) {
157+
// return lastDerivedProps
158+
// }
157159

158160
lastDerivedProps = nextProps
159161
return lastDerivedProps

0 commit comments

Comments
 (0)