-
Notifications
You must be signed in to change notification settings - Fork 323
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
Move logic calculating the index in Vector.at to a builtin method to make the performance of Vector to be on par with Array #3811
Move logic calculating the index in Vector.at to a builtin method to make the performance of Vector to be on par with Array #3811
Conversation
e147277
to
c974eb4
Compare
I'd suggest to remove |
Please make sure |
8d80034
to
2f4c3d9
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.
I like that Arrays now fail with dataflow errors as vectors - the consistency is cool.
Also really appreciating how easy and clean it is now to add a builtin type!
...ntime/src/main/java/org/enso/interpreter/node/expression/builtin/immutable/AtVectorNode.java
Outdated
Show resolved
Hide resolved
...ntime/src/main/java/org/enso/interpreter/node/expression/builtin/immutable/AtVectorNode.java
Outdated
Show resolved
Hide resolved
423272c
to
5c0a7a9
Compare
I also added some documentation to explain how I figured that (and others) out. |
The main culprit of a Vector slowdown (when compared to Array) was the normalization of the index when accessing the elements. Turns out that the Graal was very persistent on **not** inlining that particular fragment and that was degrading the results in benchmarks. Being unable to force it to do it (looks like a combination of thunk execution and another layer of indirection) we resorted to just moving the normalization to the builtin method. That makes Array and Vector perform roughly the same.
Vector.at and Array.at should both support negative indices and both return a dataflow error on invalid index.
5c0a7a9
to
baee63c
Compare
@@ -94,6 +94,29 @@ order: 7 | |||
`truffle-api`, you've done something wrong. Similarly, if you ever import | |||
anything from `org.graalvm.polyglot` in the language code, you're doing | |||
something wrong. | |||
10. Avoid | |||
[deoptimizations](https://www.graalvm.org/22.2/graalvm-as-a-platform/language-implementation-framework/Optimizing/#debugging-deoptimizations). | |||
Understanding IGV graphs can be a very time-consuming and complex process. |
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.
To put it mildly.
Pull Request Description
The main culprit of a Vector slowdown (when compared to Array) was the normalization of the index when accessing the elements. Turns out that the Graal was very persistent on not inlining that particular fragment and that was degrading the results in benchmarks.
Being unable to force it to do it (looks like a combination of thunk execution and another layer of indirection) we resorted to just moving the normalization to the builtin method. That makes Array and Vector perform roughly the same.
Moved all handling of invalid index into the builtin as well, simplifying the Enso implementation. This also meant that
Vector.unsafe_at
is now obsolete.Additionally, added support for negative indices in Array, to behave in the same way as for Vector.
Important Notes
Note that this workaround only addresses this particular perf issue. I'm pretty sure we will have more of such scenarios.
Before the change
averageOverVector
benchmark averaged around0.033 ms/op
now it does consistently0.016 ms/op
, similarly toaverageOverArray
.Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
./run ide build
and./run ide watch
.