The following patch improves the performace of reading a 10k line file
using io∆readfile from several minutes down to about half a second.

The key to this was to avoid cloning the result when reading the value from
a variable. This caused functions with lots of variable dereferencing to
become incredibly slow. This should be safe as the values are cloned before
modification anyway.

The same patch also marks the result of ⎕UCS as temp before returning the
value since it's not changed further after returning the value.

Finally, Value::clone() is changed such that it doesn't actually perform
any copying if the value is temp, and instead only marks the value
non-temp. This is the right thing to do since any caller of
clone()presumably wants to have exclusive ownership of the value.

Regards,
Elias
Index: src/QuadFunction.cc
===================================================================
--- src/QuadFunction.cc (revision 237)
+++ src/QuadFunction.cc (working copy)
@@ -2025,6 +2025,7 @@
        }
 
    Z->check_value(LOC);
+   Z->SET_temp();
    return Token(TOK_APL_VALUE1, Z);
 }
 //=============================================================================
Index: src/Symbol.cc
===================================================================
--- src/Symbol.cc       (revision 237)
+++ src/Symbol.cc       (working copy)
@@ -695,7 +695,7 @@
 
              // if we resolve a variable. the value is considered grouped.
              {
-               Token t(TOK_APL_VALUE1, get_apl_value()->clone(LOC));
+               Token t(TOK_APL_VALUE1, get_apl_value());
                move_1(tok, t, LOC);
              }
              return;
Index: src/Value.cc
===================================================================
--- src/Value.cc        (revision 237)
+++ src/Value.cc        (working copy)
@@ -1700,16 +1700,22 @@
 Value_P
 Value::clone(const char * loc) const
 {
-Value_P ret(new Value(get_shape(), loc));
+    if(is_temp()) {
+        CLEAR_temp();
+        return Value_P(const_cast<Value *>(this));
+    }
+    else {
+        Value_P ret(new Value(get_shape(), loc));
 
-const Cell * src = &get_ravel(0);
-Cell * dst = &ret->get_ravel(0);
-const ShapeItem count = nz_element_count();
+        const Cell * src = &get_ravel(0);
+        Cell * dst = &ret->get_ravel(0);
+        const ShapeItem count = nz_element_count();
 
-   loop(c, count)   dst++->init(*src++);
+        loop(c, count)   dst++->init(*src++);
 
-   ret->check_value(LOC);
-   return ret;
+        ret->check_value(LOC);
+        return ret;
+    }
 }
 //-----------------------------------------------------------------------------
 /// lrp p.138: S←⍴⍴A + NOTCHAR (per column)

Reply via email to