Menu

GCLocks & Assert performance

vranoch
2018-05-23
2018-05-23
  • vranoch

    vranoch - 2018-05-23

    Hi Gary,

    I have a guestion concerning performance impacts of the garbage collection when asserting lots of facts before actually executing the rules.

    Is it more efficient to (allow the GC to be executed only once) :

    EnvIncrementGCLocks()
    Loop
        EnvAssertString()
    EndLoop
    EnvDecrementGCLocks()
    

    than to (allow the GC to be executed X times - after each Assert)?

    Loop
        EnvAssertString()
    EndLoop
    

    Thanks Vranoch

     
  • Gary Riley

    Gary Riley - 2018-05-23

    I would be suprised if there were situations where running with the garbage collector disabled for extended periods of time did not have at least a small performance penalty. Freeing up garbage to the CLIPS internal memory pool in general will reduce the number of memory request to the operating system. Since there are so many factors that determine the amount of garbage created, I'd suggest just doing some empirical testing. For example, this small programs runs about 10% slower when the garbage collector is disabled while the facts are asserted:

    int main(
      int argc,
      char *argv[])
      {
       void *theEnv;
       double start, end;
       char buffer[256];
       long i;
    
       theEnv = CreateEnvironment();
    
       start = gentime();
    
       EnvBuild(theEnv,"(deftemplate foo (slot v1) (slot v2) (slot v3))");
    
       //EnvIncrementGCLocks(theEnv);
       for (i = 0; i < 100000; i++)
         {
          sprintf(buffer,"(foo (v1 %ld) (v2 %ld) (v3 %ld))",i,i * 2, i *3);
          EnvAssertString(theEnv,buffer);
         }
       //EnvDecrementGCLocks(theEnv);
       end = gentime();
    
       printf("total time = %g\n",end - start);
    
       return(-1);
      }
    
     

Log in to post a comment.