enso-org / enso

Hybrid visual and textual functional programming.
https://ensoanalytics.com
Apache License 2.0
7.36k stars 324 forks source link

Unify & speed access to array-like objects behind `ArrayXyzNode` #6299

Closed JaroslavTulach closed 1 year ago

JaroslavTulach commented 1 year ago

Currently the Enso engine is using InteropLibrary to read elements from array-like objects. However that's not enough - we have to guarantee that such elements are converted to Enso supported objects using HostValueToEnsoNode. As various incidents indicate:

we often forget to do such conversion.

The standard Truffle way of avoiding such problem and also making the array-like object access fast is to define nodes that specialize according to the data (Vector, Array, foreign object). Let's define:

and replace all array-like access with these nodes rather than using InteropLibrary directly.

JaroslavTulach commented 1 year ago

While investigating #7420 it turned out that eliminating need for HostValueToEnsoNode conversion can speed things up:

diff --git engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Vector.java engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Vector.java
index a966d47a5d..e9e283deaa 100644
--- engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Vector.java
+++ engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Vector.java
@@ -119,7 +119,7 @@ public final class Vector implements TruffleObject {
       }
       return WithWarnings.wrap(EnsoContext.get(interop), toEnso.execute(v), extracted);
     }
-    return toEnso.execute(v);
+    return v;
   }

   public static Vector fromArray(Object arr) {

the runtime/benchOnly caseBench3 benchmark is 10% faster. Eliminate need for this check for Enso only Vectors.

JaroslavTulach commented 1 year ago

The handling of warnings is also something that would better be unified as

demonstrates.

enso-bot[bot] commented 1 year ago

Jaroslav Tulach reports a new STANDUP for yesterday (2023-08-10):

Progress: - cleanup array-like classes: https://github.com/enso-org/enso/pull/7544

Next Day: Array access unification

enso-bot[bot] commented 1 year ago

Jaroslav Tulach reports a new STANDUP for yesterday (2023-08-11):

Progress: - Array access unification - https://github.com/enso-org/enso/pull/7544

Next Day: Finish array access unification

enso-bot[bot] commented 1 year ago

Jaroslav Tulach reports a new STANDUP for yesterday (2023-08-13):

Progress: - Array & Vector work: https://github.com/enso-org/enso/pull/7544 It should be finished by 2023-08-14.

Next Day: Finish array access unification

enso-bot[bot] commented 1 year ago

Jaroslav Tulach reports a new STANDUP for yesterday (2023-08-14):

Progress: - ArrayBuilder builtin: https://github.com/enso-org/enso/pull/7544/commits/ae89884204e4353534981689d826be99a44e38c6

Next Day: Finish array access unification