From 609794ebf2e192ff3e2cc32ac8e32a038cd5b67d Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Thu, 4 Jan 2024 11:42:39 +0100 Subject: [PATCH] configurable gc threshold --- src/support/include/Options.h | 1 + src/vm/include/MemoryContext.h | 3 ++- src/vm/src/VM.cpp | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/support/include/Options.h b/src/support/include/Options.h index a8883da..d96cdfc 100644 --- a/src/support/include/Options.h +++ b/src/support/include/Options.h @@ -40,6 +40,7 @@ private: const static inline std::unordered_map> _defaults{{"cell_limit", 50000U}, {"command_strs", false}, {"default_log_level", 1U}, + {"gc_threshold", 50U}, {"repl", true}}; std::unordered_map> _current = _defaults; diff --git a/src/vm/include/MemoryContext.h b/src/vm/include/MemoryContext.h index 3912c64..a65c859 100644 --- a/src/vm/include/MemoryContext.h +++ b/src/vm/include/MemoryContext.h @@ -95,7 +95,8 @@ private: std::lock_guard tmplg(_new_roots_lock); Handle ret(cell); _temp_cells.emplace_back(cell); - if ((_cells_num + _temp_cells.size() + 1) >= (size_t) (Options::get("cell_limit") / 2)) { + if ((_cells_num + _temp_cells.size()) >= + ((Options::get("cell_limit") * Options::get("gc_threshold")) / 100ULL)) { request_gc(); } return ret; diff --git a/src/vm/src/VM.cpp b/src/vm/src/VM.cpp index dc25b5e..781361f 100644 --- a/src/vm/src/VM.cpp +++ b/src/vm/src/VM.cpp @@ -35,7 +35,7 @@ void VM::step() { if (!_d.null()) out << "d:" << _d << "\n"; }, Logger::TRACE); - + switch (poppedCmd) { case NIL: { _s.push(nullptr); @@ -300,6 +300,7 @@ void VM::step() { std::string read; std::getline(_instream, read); _s.push(Parser::parse_str(read)); + break; } default: throw std::invalid_argument("Unknown command: " + std::to_string(poppedCmd));