From 40565b4a089f44fdcb16f4ed0080b0ca3755e4aa Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 13 Dec 2022 11:55:14 -0300 Subject: Revamp of GC parameters More uniformity when handling GC parameters + avoid divisions by 100 when applying them. --- lgc.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'lgc.c') diff --git a/lgc.c b/lgc.c index c2b0535d..90a49091 100644 --- a/lgc.c +++ b/lgc.c @@ -1030,14 +1030,10 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { /* ** Set the "time" to wait before starting a new GC cycle; cycle will ** start when number of objects in use hits the threshold of -** approximately ('marked' * pause / 100). (A direct multiplication -** by 'pause' may overflow, and a direct division by 100 may undeflow -** to zero. So, the division is done in two steps. 8 * 12 is near 100 -** and the division by 8 is cheap.) +** approximately (marked * pause / 100). */ static void setpause (global_State *g) { - unsigned int pause = getgcparam(g->gcpause); - l_obj threshold = g->marked / 8 * pause / 12; + l_obj threshold = applygcparam(g, gcpause, g->marked); l_obj debt = gettotalobjs(g) - threshold; if (debt > 0) debt = 0; luaE_setdebt(g, debt); @@ -1289,7 +1285,7 @@ static void atomic2gen (lua_State *L, global_State *g) { ** total number of objects grows 'genminormul'%. */ static void setminordebt (global_State *g) { - luaE_setdebt(g, -(gettotalobjs(g) / 100) * g->genminormul); + luaE_setdebt(g, -applygcparam(g, genminormul, gettotalobjs(g))); } @@ -1387,7 +1383,7 @@ static void genmajorstep (lua_State *L, global_State *g) { */ static void genstep (lua_State *L, global_State *g) { l_obj majorbase = g->GClastmajor; /* count after last major collection */ - l_obj majorinc = (majorbase / 100) * getgcparam(g->genmajormul); + l_obj majorinc = applygcparam(g, genmajormul, majorbase); if (g->GCdebt > 0 && gettotalobjs(g) > majorbase + majorinc) { /* do a major collection */ enterinc(g); @@ -1601,7 +1597,7 @@ void luaC_runtilstate (lua_State *L, int statesmask) { */ static void incstep (lua_State *L, global_State *g) { l_obj stepsize = cast(l_obj, 1) << g->gcstepsize; - l_obj work2do = stepsize * getgcparam(g->gcstepmul) / 100; + l_obj work2do = applygcparam(g, gcstepmul, stepsize); do { /* repeat until pause or enough "credit" (negative debt) */ l_obj work = singlestep(L); /* perform one single step */ work2do -= work; -- cgit v1.2.3-55-g6feb