From efa63ca96abdd6582a869cfc5cd8d047647d7ca9 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Mon, 7 Apr 2025 16:52:45 +0200 Subject: [PATCH] Pg: Discard temporary hash keys earlier in $st->kv? methods Saves some memory for large query results, didn't notice much of a performance difference. --- c/pgst.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/c/pgst.c b/c/pgst.c index 1e01392..e5a2a3d 100644 --- a/c/pgst.c +++ b/c/pgst.c @@ -460,9 +460,11 @@ static SV *fupg_st_kvv(pTHX_ fupg_st *st) { HV *hv = newHV(); SV *sv = sv_2mortal(newRV_noinc((SV *)hv)); for (i=0; ikvv() query results", SvPV_nolen(key)); hv_store_ent(hv, key, st->nfields == 1 ? &PL_sv_yes : fupg_st_getval(aTHX_ st, i, 1), 0); + FREETMPS; } return sv; } @@ -474,10 +476,12 @@ static SV *fupg_st_kva(pTHX_ fupg_st *st) { HV *hv = newHV(); SV *sv = sv_2mortal(newRV_noinc((SV *)hv)); for (i=0; ikva() query results", SvPV_nolen(key)); AV *row = st->nfields == 1 ? newAV() : newAV_alloc_x(st->nfields-1); hv_store_ent(hv, key, newRV_noinc((SV *)row), 0); + FREETMPS; for (j=1; jnfields; j++) av_push_simple(row, fupg_st_getval(aTHX_ st, i, j)); } @@ -492,10 +496,12 @@ static SV *fupg_st_kvh(pTHX_ fupg_st *st) { HV *hv = newHV(); SV *sv = sv_2mortal(newRV_noinc((SV *)hv)); for (i=0; ikvh() query results", SvPV_nolen(key)); HV *row = newHV(); hv_store_ent(hv, key, newRV_noinc((SV *)row), 0); + FREETMPS; for (j=1; jnfields; j++) { const char *key = PQfname(st->result, j); hv_store(row, key, -strlen(key), fupg_st_getval(aTHX_ st, i, j), 0);