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


##########
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:
   Since we are stringifying the whole table, is it worth using an array view 
here?



-- 
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