Skip to content

Commit e3092fe

Browse files
committed
Performance updates.
Benchmarking originally showed fairly high memory usage and a slow garbage collection schedule when creating 1000 contexts. To avoid this, a garbage collection cycle was put into place after each function execution. This solved the memory bloat, but slowed down function calls. I decided to revisit that decision. Memory limits were an arbitrary 256MB when the concept was put into place in plv8 in 2019, and 512MB is a decent default with modern hardware. It can still be changed to 256MB with a GUC if desired. The benchmark was able to trigger an out of memory issue, but under very artificial conditions: * 1000 roles, and thus quickjs contexts were being created * Each context carries an allocation of 190kb on MacOS (untested on Linux) Even though the roles are deleted, there is no mechanism for postgres to tell pljs this, and those contexts essentially become zombies in the cache. Since the benchmark is an extremely artifical (and meant specifically to test the startup time of pljs contexts), it is unlikely that this behavior will be able to be triggered in production. At worst case, a memory limit is hit, and the limit needs to be increased via the GUC. Thus garbage collection is left to run when memory pressure exists, rather with every function execution, and more memory can be allocated to slow memory pressure by default. This speeds up contex creation and function calls slightly, and speeds up the artificial context creation significantly.
1 parent d87dcf4 commit e3092fe

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ regression.out
99
.depend
1010
docs/html
1111
docs/latex
12+
docs/xml
1213
pljs--*.sql
1314
compile_commands.json

docs/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ Released _August 20, 2025_.
2828
Released _August 20, 2025_.
2929

3030
- PGXN release went out with an incorrect control file
31+
32+
### 1.1.0
33+
34+
- Up memory default limit to 512MB
35+
- Remove unnecessary include from modules.c
36+
- Remove extra running of GC after each execution

src/pljs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ void pljs_guc_init(void) {
104104

105105
DefineCustomIntVariable("pljs.memory_limit",
106106
gettext_noop("Runtime limit in MBytes"),
107-
gettext_noop("The default value is 256 MB"),
108-
(int *)&configuration.memory_limit, 256, 256, 3096,
107+
gettext_noop("The default value is 512 MB"),
108+
(int *)&configuration.memory_limit, 512, 256, 3096,
109109
PGC_SUSET, 0, NULL, NULL, NULL);
110110

111111
DefineCustomStringVariable(
@@ -1043,7 +1043,7 @@ static Datum call_function(FunctionCallInfo fcinfo, pljs_context *context,
10431043

10441044
JSValue ret = JS_Call(context->ctx, context->js_function, JS_UNDEFINED,
10451045
context->function->inargs, argv);
1046-
JS_RunGC(rt);
1046+
10471047
SPI_finish();
10481048

10491049
if (JS_IsException(ret)) {

0 commit comments

Comments
 (0)