From 4693ad0264146574dbdb09feebc4b513aee7d3c5 Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Mon, 10 Aug 2026 21:04:57 +0100 Subject: [PATCH] Inline `setnodevector(..., 0)`. `setnodevector` is really two functions: a general purpose function that can be called with an arbitrary number of run-time values; and a special, fast, case for zero, which is called a lot, mostly in `luaH_new`. The easiest way to inline this into a trace is to manually inline it! This speeds up Fannkuch and Mandlebrot, without any obvious ill effects on anything else. --- src/ltable.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ltable.c b/src/ltable.c index b7f88f6..40ed1f6 100644 --- a/src/ltable.c +++ b/src/ltable.c @@ -803,7 +803,15 @@ Table *luaH_new (lua_State *L) { t->flags = maskflags; /* table has no metamethod fields */ t->array = NULL; t->asize = 0; +#ifdef USE_YK + // We don't want to make `setnodevector` "unroll" because the non-zero case + // may not be constant. + t->node = cast(Node *, dummynode); /* use common 'dummynode' */ + t->lsizenode = 0; + setdummy(t); /* signal that it is using dummy node */ +#else setnodevector(L, t, 0); +#endif return t; }