Skip to content

perf: replace accumulator spread with assignment#274

Merged
Fdawgs merged 1 commit intomainfrom
perf/accum
Apr 9, 2025
Merged

perf: replace accumulator spread with assignment#274
Fdawgs merged 1 commit intomainfrom
perf/accum

Conversation

@Fdawgs
Copy link
Member

@Fdawgs Fdawgs commented Apr 7, 2025

Stumbled across this blog post a while ago, which covers why using spread ({...obj}) syntax in accumulators like reduce is a bad idea.

TL;DR: it causes a time complexity of O(n^2) instead of O(n) because it's creating an increasingly growing new object on every iteration. Whilst with assignment we're mutating the accumulator rather than creating a new object.

Checklist

@aboutlo
Copy link
Collaborator

aboutlo commented Apr 9, 2025

LGTM

@Fdawgs Fdawgs merged commit 8714db3 into main Apr 9, 2025
13 checks passed
@Fdawgs Fdawgs deleted the perf/accum branch April 9, 2025 12:00
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.

3 participants