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

Use ArraySlice to slice a Vector #3724

Merged
merged 13 commits into from
Sep 23, 2022
Merged

Conversation

jdunkerley
Copy link
Member

@jdunkerley jdunkerley commented Sep 20, 2022

[ci no changelog needed]

Pull Request Description

Use an ArraySlice to slice Vector.
Avoids memory copying for the slice function.

Important Notes

Test Ref New
New Vector 71.9 71.0
Append Single 26.0 27.7
Append Large 15.1 14.9
Sum 156.4 165.8
Drop First 20 and Sum 171.2 165.3
Drop Last 20 and Sum 170.7 163.0
Filter 76.9 76.9
Filter With Index 166.3 168.3
Partition 278.5 273.8
Partition With Index 392.0 393.7
Each 101.9 102.7
  • Note: the performance of New and Append has got slower from previous tests.

Checklist

Please include the following checklist in your PR:

  • The documentation has been updated if necessary.
  • All code conforms to the
    Scala,
    Java,
    and
    Rust
    style guides.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed: Enso GUI was tested when built using BOTH
      ./run ide build and ./run ide watch.

@jdunkerley jdunkerley requested a review from hubertp September 20, 2022 15:49
@jdunkerley jdunkerley force-pushed the wip/jd/vector-slice-182880080 branch from 13973fb to 19bbb0c Compare September 21, 2022 16:18
@jdunkerley jdunkerley marked this pull request as ready for review September 21, 2022 16:37
@jdunkerley jdunkerley force-pushed the wip/jd/vector-slice-182880080 branch 2 times, most recently from abfc064 to 151c749 Compare September 22, 2022 16:24
Copy link
Member

@radeusgd radeusgd left a comment

Choose a reason for hiding this comment

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

Looks good to me overall, just a few small comments and a question on implementation that would be good if can be answered before merge.

Comment on lines 23 to 27
if (CompilerDirectives.inInterpreter()) {
if (!InteropLibrary.getUncached().hasArrayElements(storage)) {
throw new IllegalStateException("Vector needs array-like delegate, but got: " + storage);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I think I don't understand why this check is performed only in the interpreter. Won't this affect semantics depending on optimization levels?

Copy link
Member

Choose a reason for hiding this comment

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

Anyway, if left as-is I think it would be beneficial to add a short comment explaining why this is only checked in interpreter.

Unless there is some obvious reason that every Truffle developer should understand immediately, I think such an explanation will help future developers understand this decision.

Copy link
Member

Choose a reason for hiding this comment

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

We could do the check as assert. Asserts are ignored when Truffle does its PE compilation. We just need to make sure we run our tests with -ea.

Copy link
Member

Choose a reason for hiding this comment

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

Why can't the check be there always?

@Builtin.Specialize
@Builtin.WrapException(from = UnsupportedMessageException.class, to = PanicException.class)
public final Vector slice(long start, long end, InteropLibrary interop)
throws UnsupportedMessageException {
Copy link
Member

Choose a reason for hiding this comment

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

In what circumstances is UnsupportedMessageException thrown?

Copy link
Member Author

Choose a reason for hiding this comment

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

Only if the backing storage no longer can answer the interop.getArraySize call - shouldn't happen.

test/Benchmarks/src/Vector.enso Show resolved Hide resolved
test/Tests/src/Data/Vector_Spec.enso Show resolved Hide resolved
Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

Not bad. If that works, it can go in. There is VectorBenchmarks.java - consider adding a sliced check in there.

Comment on lines 23 to 27
if (CompilerDirectives.inInterpreter()) {
if (!InteropLibrary.getUncached().hasArrayElements(storage)) {
throw new IllegalStateException("Vector needs array-like delegate, but got: " + storage);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

We could do the check as assert. Asserts are ignored when Truffle does its PE compilation. We just need to make sure we run our tests with -ea.

test/Tests/src/Data/Vector_Spec.enso Show resolved Hide resolved
jdunkerley and others added 9 commits September 23, 2022 09:16
Parameters of type InteropLibrary are currently correctly generated only
when annotated with `Builtin.Specialized`. Should eventually get rid of
this limitation and merge the logic into both variants.
@jdunkerley jdunkerley force-pushed the wip/jd/vector-slice-182880080 branch from 151c749 to 0df33f0 Compare September 23, 2022 08:54
@jdunkerley jdunkerley added the CI: Ready to merge This PR is eligible for automatic merge label Sep 23, 2022
@mergify mergify bot merged commit a3de3c6 into develop Sep 23, 2022
@mergify mergify bot deleted the wip/jd/vector-slice-182880080 branch September 23, 2022 15:13
mergify bot pushed a commit that referenced this pull request Sep 27, 2022
Each builtin `makeFunction` method has to be currently registered for reflection. Adding registration of `SliceVectorMethodGen` to make following example work ag

```bash
enso$ sbt engine-runner-native/buildNativeImage
enso$ ./runner --run engine/runner-native/src/test/resources/Factorial.enso 6
```

# Important Notes
Regression caused by #3724 - Once the above code is executed in the CI, we'll discover such breakages before integration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants