From d3c33c2d1c71c760eb5efe7a41111146cc07cb11 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Thu, 11 Jan 2024 21:08:31 +0800 Subject: [PATCH] increase gc threshold --- include/pocketpy/config.h | 5 +++++ include/pocketpy/gc.h | 3 +-- src/gc.cpp | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/pocketpy/config.h b/include/pocketpy/config.h index 1574eabf..97835a98 100644 --- a/include/pocketpy/config.h +++ b/include/pocketpy/config.h @@ -24,6 +24,11 @@ #define PK_ENABLE_CEVAL_CALLBACK 0 #endif +// GC min threshold +#ifndef PK_GC_MIN_THRESHOLD // can be overrided by cmake +#define PK_GC_MIN_THRESHOLD 32768 +#endif + // Whether to use `std::function` to do bindings or not // By default, functions to be binded must be a C function pointer without capture // However, someone thinks it's not convenient. diff --git a/include/pocketpy/gc.h b/include/pocketpy/gc.h index c7a869d0..fa1424e2 100644 --- a/include/pocketpy/gc.h +++ b/include/pocketpy/gc.h @@ -16,8 +16,7 @@ struct ManagedHeap{ ManagedHeap(VM* vm): vm(vm) {} - static const int kMinGCThreshold = 3072; - int gc_threshold = kMinGCThreshold; + int gc_threshold = PK_GC_MIN_THRESHOLD; int gc_counter = 0; /********************/ diff --git a/src/gc.cpp b/src/gc.cpp index 5c1daf7d..3f5a75c3 100644 --- a/src/gc.cpp +++ b/src/gc.cpp @@ -36,7 +36,7 @@ namespace pkpy{ gc_counter = 0; collect(); gc_threshold = gen.size() * 2; - if(gc_threshold < kMinGCThreshold) gc_threshold = kMinGCThreshold; + if(gc_threshold < PK_GC_MIN_THRESHOLD) gc_threshold = PK_GC_MIN_THRESHOLD; #endif }