Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(issue 534): replace reduce + spread operator with performant variant #538

Merged
merged 6 commits into from
Jun 2, 2024

Conversation

flowreaction
Copy link
Contributor

This PR fixes the issue brought up in #534. The performance implications of reduce and spread are quite heavy so replacing them with regular loops with array mutation increased performance on my machine mulitple magnitudes, for very large arrays north of 20.000x faster.

┌─────────┬─────────────┬─────────────────────┬─────────────────────┬────────────────┬─────────────┐
│ (index) │ numElements │ timeOld             │ timeNew             │ areResultsSame │ improvement │
├─────────┼─────────────┼─────────────────────┼─────────────────────┼────────────────┼─────────────┤
│ 0       │ 100         │ 0.08329199999997172 │ 0.09158300000001418 │ true           │ '0x'        │
│ 1       │ 1000        │ 2.159749999999974   │ 0.132000000000005   │ true           │ '16x'       │
│ 2       │ 10000       │ 53.110708999999986  │ 0.5692910000000211  │ true           │ '93x'       │
│ 3       │ 100000      │ 9115.303124999999   │ 2.2292080000006536  │ true           │ '4089x'     │
│ 4       │ 500000      │ 310282.093833       │ 11.678125000034925  │ true           │ '26569x'    │
└─────────┴─────────────┴─────────────────────┴─────────────────────┴────────────────┴─────────────┘

The `combineResultListFast` utility function is added to the `_internals/utils.ts` file. This function combines a list of `Result` objects and short circuits on the first `Err` value encountered. It returns a `Result` object containing the combined list of `Ok` values or the first `Err` value.
Copy link
Owner

@supermacro supermacro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thank you for the improvement :)

@supermacro supermacro merged commit 2062c32 into supermacro:master Jun 2, 2024
4 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