Changeset: 83cd98002361 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=83cd98002361
Modified Files:
        monetdb5/modules/mal/mal_weld.c
Branch: mal-weld
Log Message:

naive weld compiled code cache


diffs (85 lines):

diff --git a/monetdb5/modules/mal/mal_weld.c b/monetdb5/modules/mal/mal_weld.c
--- a/monetdb5/modules/mal/mal_weld.c
+++ b/monetdb5/modules/mal/mal_weld.c
@@ -95,6 +95,45 @@ static int getMalTypeFromWidth(int width
                return TYPE_lng;
 }
 
+struct progCache {
+       str prog;
+       weld_module_t module;
+};
+
+struct progCache *progCache = NULL;
+int progCacheSize = 0;
+int progCacheMaxSize = 0;
+
+static void addToProgCache(str prog, weld_module_t module) {
+       int i;
+       for (i = 0; i < progCacheSize; i++) {
+               if (strcmp(progCache[i].prog, prog) == 0) {
+                       return;
+               }
+       };
+       if (progCacheSize == progCacheMaxSize) {
+               if (progCacheMaxSize == 0) {
+                       progCacheMaxSize = 10;
+               } else {
+                       progCacheMaxSize *= 2;
+               }
+               progCache = realloc(progCache, progCacheMaxSize * sizeof(struct 
progCache));
+       }
+       progCache[progCacheSize].prog = strdup(prog);
+       progCache[progCacheSize].module = module;
+       progCacheSize++;
+}
+
+static weld_module_t* getCachedModule(str prog) {
+       int i;
+       for (i = 0; i < progCacheSize; i++) {
+               if (strcmp(progCache[i].prog, prog) == 0) {
+                       return &progCache[i].module;
+               }
+       }
+       return NULL;
+}
+
 void getOrSetStructMember(char **addr, int type, const void *value, int op) {
        if (type == TYPE_bte) {
                getOrSetStructMemberImpl(addr, char, value, op);
@@ -271,13 +310,21 @@ WeldRun(Client cntxt, MalBlkPtr mb, MalS
        weld_conf_set(conf, "weld.threads", nrThreads);
        weld_conf_set(conf, "weld.memory.limit", memLimit);
        weld_conf_set(conf, "weld.optimization.applyExperimentalTransforms", 
"true");
-       long start = getTimeNowMs();
-       weld_module_t m = weld_module_compile(wstate->program, conf, e);
-       if (weld_error_code(e)) {
-               throw(MAL, "weld.run", PROGRAM_GENERAL ": %s", 
weld_error_message(e));
+       weld_module_t *cachedModule = getCachedModule(wstate->program);
+       weld_module_t m;
+       if (cachedModule != NULL) {
+               m = *cachedModule;
+               fprintf(stderr, "0,");
+       } else {
+               long start = getTimeNowMs();
+               m = weld_module_compile(wstate->program, conf, e);
+               if (weld_error_code(e)) {
+                       throw(MAL, "weld.run", PROGRAM_GENERAL ": %s", 
weld_error_message(e));
+               }
+               long elapsed = getTimeNowMs() - start;
+               fprintf(stderr, "%ld,", elapsed);
+               addToProgCache(wstate->program, m);
        }
-       long elapsed = getTimeNowMs() - start;
-       fprintf(stderr, "%ld,", elapsed);
 
        /* Prepare the input for Weld. We're building an array that has the 
layout of a struct */
        /* Max possible size is when we only have string bats: 2 ptrs for theap 
and tvheap and 4 lngs
@@ -398,7 +445,6 @@ WeldRun(Client cntxt, MalBlkPtr mb, MalS
        weld_value_free(arg);
        weld_value_free(result);
        weld_conf_free(conf);
-       weld_module_free(m);
        free(inputStruct);
        free(wstate->program);
        free(wstate->groupDeps);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to