domoritz commented on code in PR #44247:
URL: https://github.com/apache/arrow/pull/44247#discussion_r1779658502


##########
js/src/table.ts:
##########
@@ -238,17 +238,30 @@ export class Table<T extends TypeMap = any> {
      *
      * @returns An Array of Table rows.
      */
-    public toArray() {
+    public toArray(): Array<Struct<T>['TValue']> {
         return [...this];
     }
 
+    /**
+     * Return a JavaScript Array view of the Table rows.
+     *
+     * It is a lightweight read-only proxy that delegates to the table. 
Accessing elements has some
+     * overhead compared to the regular array returned by `toArray()` because 
of this indirection,
+     * but it avoids potentially large memory allocation.
+     *
+     * @returns An Array proxy to the Table rows.
+     */
+    public toArrayView(): Array<Struct<T>['TValue']> {
+        return new Proxy([] as Array<Struct<T>['TValue']>, new 
TableArrayProxyHandler(this));
+    }
+
     /**
      * Returns a string representation of the Table rows.
      *
      * @returns A string representation of the Table rows.
      */
     public toString() {
-        return `[\n  ${this.toArray().join(',\n  ')}\n]`;
+        return `[\n  ${this.toArrayView().join(',\n  ')}\n]`;

Review Comment:
   I understand the difference but I wonder whether this change introduces a 
performance regression since "the proxy adds some overhead to direct array 
access."
   
   I'm not against this change but want to make sure we have thought through 
the implications. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to