-
Notifications
You must be signed in to change notification settings - Fork 318
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
Improve Vector #3232
Improve Vector #3232
Conversation
distribution/lib/Standard/Base/0.2.32-SNAPSHOT/src/Data/Vector.enso
Outdated
Show resolved
Hide resolved
ac09fd9
to
be7c069
Compare
107fd5d
to
ed889ae
Compare
Added benchmarks for filter and each. Their results from before changes:
|
The same benchmarks AFTER the changes:
We can see roughly 9x improvement for |
@@ -303,8 +324,15 @@ type Vector | |||
[1, 2, 3, 4, 5].filter (> 3) | |||
filter : (Any -> Boolean) -> Vector Any | |||
filter predicate = | |||
check acc ix = if predicate ix then acc + [ix] else acc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My exact face expression after seeing it.
The benchmarks were deliberately smaller so that the old super-slow version of filter would finish in a sane amount of time. Below are the results after this change.
|
distribution/lib/Standard/Base/0.2.32-SNAPSHOT/src/Data/Vector.enso
Outdated
Show resolved
Hide resolved
Why is this super-slow? In comparison to what? Asking because it may indeed be worth comparing, for example with pure-Java code - and there will probably be a noticeable difference. But fair, maybe filtering 1M elements should indeed take less than 40ms. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some decent improvements in here - that help should help with the high level functions.
Just out of curiosity - and to get a general feeling of what should I expect of these functions, I wrote a very small benchmark in Java to have a baseline comparison (of course it is not a fully-fledged comparison as I didn't want to waste time on it, just get a general feeling of what would be the expected performance). So using the same parameters, I also changed the callback in each to compute In Java unboxed iteration takes about ~3ms, boxed iteration is about 5ms (boxed is a better baseline because our Vector is boxed to allow mixed types, theoretically we could also have an unboxed Vector for integers, but it could have some issues with overflows as normally we'd want to switch to BigInts). In Enso each takes about 14ms. So yeah it is indeed slower, but I wouldn't say super-slow. Filter is a bit worse, since our implementation takes ~50ms and simple Java code seems to run in ~10ms. Java code for reference: |
2a74cf6
to
387a227
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a useful pattern emerging, you should formalize it.
distribution/lib/Standard/Base/0.2.32-SNAPSHOT/src/Data/Vector.enso
Outdated
Show resolved
Hide resolved
distribution/lib/Standard/Base/0.2.32-SNAPSHOT/src/Data/Vector.enso
Outdated
Show resolved
Hide resolved
distribution/lib/Standard/Base/0.2.32-SNAPSHOT/src/Data/Vector.enso
Outdated
Show resolved
Hide resolved
distribution/lib/Standard/Base/0.2.32-SNAPSHOT/src/Data/Vector.enso
Outdated
Show resolved
Hide resolved
a682817
to
6a5ab36
Compare
Improve each performance ~2-3x Improve filter performance ~50-60x
6a5ab36
to
70ff6d6
Compare
Pull Request Description
Important Notes
Checklist
Please include the following checklist in your PR: