Changeset: 3b053e7383ee for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3b053e7383ee
Modified Files:
        monetdb5/optimizer/opt_xid.c
Branch: xid
Log Message:

Synchronize decompression
The decompression step should be postpone to when the data is
needed to execute a normal instruction. This can be solved with
the language.wait operation.

Also (de) compression is considered if the instructions involved
are far apart.


diffs (134 lines):

diff --git a/monetdb5/optimizer/opt_xid.c b/monetdb5/optimizer/opt_xid.c
--- a/monetdb5/optimizer/opt_xid.c
+++ b/monetdb5/optimizer/opt_xid.c
@@ -22,21 +22,28 @@
 /*
  * Inject OID list compressions, to be used after garbagecontrol
  */
+#define MIN_DISTANCE 10
+
 int 
 OPTxidImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
        int type, i, j, se, limit, v;
-       InstrPtr q, p=0, *old= mb->stmt;
+       InstrPtr q, qs, p=0, *old= mb->stmt;
        int actions = 0, cnt;
-       int *alias;
+       int *compressed, *def;
        Lifespan span;
 
        (void) pci;
        (void) stk;             /* to fool compilers */
 
-       alias = GDKzalloc(sizeof(int) * mb->vtop);
-       if (alias ==0)
+       compressed = GDKzalloc( 2 * sizeof(int) * mb->vtop);
+       if (compressed ==0)
                return 0;
+       def = GDKzalloc( 2 * sizeof(int) * mb->vtop);
+       if (def ==0) {
+               GDKfree(compressed);
+               return 0;
+       }
 
        span = setLifespan(mb);
        if ( span == NULL)
@@ -65,50 +72,64 @@ OPTxidImplementation(Client cntxt, MalBl
                 */
                cnt = 0;
                for ( j =p->retc; j< p->argc; j++)
-               if (alias[getArg(p,j)] ) cnt++;
+               if (compressed[getArg(p,j)] ) cnt++;
                /* at least one decompress needed */
                if ( cnt ){
                        cnt = 0;
                        for ( j =p->retc; j< p->argc; j++)
                        if ( isaBatType(getVarType(mb,getArg(p,j))) ) cnt++;
                }
-               cnt = 0;
+
                /* at least two BATs used, synchronise their access */
-               if ( cnt >= 2 ){
-                       q = newStmt(mb,languageRef,syncRef);
-                       q->retc = q->argc = 0;
+               if ( cnt >= 200 ){
+                       qs = newStmt(mb,languageRef,syncRef);
+                       qs->retc = qs->argc = 0;
                        for ( j =p->retc; j< p->argc; j++)
                        if ( isaBatType(getVarType(mb, getArg(p,j))) ) {
                                v = newTmpVariable(mb, getVarType(mb, 
getArg(p,j)));
-                               q= pushReturn(mb, q, v);
-                               if ( alias[getArg(p,j)])
-                                       q= pushArgument(mb,q, 
alias[getArg(p,j)]);
-                               else
-                                       /* should avoid compressing 
non-compressed bats todo */
-                                       q= pushArgument(mb, q, getArg(p,j));
-                               alias[getArg(p,j)] = v;
+                               assert(v < 2* mb->vtop);
+                               qs= pushReturn(mb, qs, v);
+                               if ( compressed[getArg(p,j)] ) {
+                                       qs= pushArgument(mb, qs, 
compressed[getArg(p,j)]);
+                                       /* actually decompress when there is 
not a direct flow into the instruction */
+                                       if ( compressed[getArg(p,j)] && i - 
def[getArg(p,j)] > MIN_DISTANCE ){
+                                               mnstr_printf(GDKout,"#var %d 
def use %d\n",getArg(p,j), i - def[getArg(p,j)]);
+                                               q = 
newStmt(mb,"xid","decompress");
+                                               q= pushArgument(mb, q, 
compressed[getArg(p,j)]);
+                                               setVarType(mb, getArg(q,0), 
getVarType(mb, getArg(p,j)));
+                                               getArg(p,j) = getArg(q,0);
+                                       } else
+                                               getArg(p,j) = v;
+                                } else {
+                                       qs= pushArgument(mb, qs, getArg(p,j));
+                                       getArg(p,j) = v;
+                               }
                        }
-               }
+               } else
+                       for ( j =p->retc; j< p->argc; j++)
+                       /* actually decompress when there is not a direct flow 
into the instruction */
+                       if ( compressed[getArg(p,j)] && i - def[getArg(p,j)] > 
MIN_DISTANCE ){
+                               mnstr_printf(GDKout,"#var %d def use 
%d\n",getArg(p,j), i - def[getArg(p,j)]);
+                               q = newStmt(mb,"xid","decompress");
+                               q= pushArgument(mb,q, compressed[getArg(p,j)]);
+                               setVarType(mb, getArg(q,0), getVarType(mb, 
getArg(p,j)));
+                               getArg(p,j) = getArg(q,0);
+                       } 
 
-               for ( j =p->retc; j< p->argc; j++)
-               if ( alias[getArg(p,j)]){
-                       q = newStmt(mb,"xid","decompress");
-                       q= pushArgument(mb,q, alias[getArg(p,j)]);
-                       setVarType(mb, getArg(q,0), getVarType(mb, 
getArg(p,j)));
-                       getArg(p,j) = getArg(q,0);
-               }
                pushInstruction(mb,p);
 
                /* compress the result, if at least one column is :oid */
                for (j = 0 ; j < p->retc ; j++) {
                        type= getVarType(mb,getArg(p,j));
-                       if ((getTailType(type) == TYPE_oid || getHeadType(type) 
== TYPE_oid) && alias[getArg(p,j)] == 0) {
+                       if ((getTailType(type) == TYPE_oid || getHeadType(type) 
== TYPE_oid) && compressed[getArg(p,j)] == 0) {
                                //mnstr_printf(GDKout,"#got candidate %d head 
%d tail %d\n",getArg(p,j), getHeadType(getVarType(mb,getArg(p,j))),  
getTailType(getVarType(mb,getArg(p,j))));
                                /* don't compress if you immediately eat the 
result */
-                               if (getEndLifespan(span, getArg(p,j)) > i + 1) {
+                               if (getEndLifespan(span, getArg(p,j)) >= i + 
MIN_DISTANCE) {
                                        q = newStmt(mb,"xid","compress");
                                        q= pushArgument(mb,q, getArg(p,j));
-                                       alias [getArg(p,j)] = getArg(q,0);
+                                       compressed [getArg(p,j)] = getArg(q,0);
+                                       def[getArg(p,j)] = i;
+                               mnstr_printf(GDKout,"#var %d def 
%d\n",getArg(p,j), i);
                                }
                        }
                }
@@ -116,7 +137,8 @@ OPTxidImplementation(Client cntxt, MalBl
        DEBUGoptimizers
                mnstr_printf(cntxt->fdout,"#opt_xid: %d statements removed\n", 
actions);
        GDKfree(old);
-       GDKfree(alias);
+       GDKfree(compressed);
+       GDKfree(def);
        /* we may have uncovered new use-less operations */
        return actions;
 }
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to