From ffd4cd94a17371e9fbc873a1eff678387377b42e Mon Sep 17 00:00:00 2001 From: James Onnen Date: Sun, 29 Mar 2020 03:35:15 -0700 Subject: [PATCH] Avoid reallocating another table for the _consumers() metatable, leading to a 5%-10% speed up of the trivial Promise.new(function() end) case --- lib/init.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/init.lua b/lib/init.lua index ccc90fd..1ab7e14 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -8,6 +8,10 @@ local ERROR_NON_PROMISE_IN_LIST = "Non-promise value passed into %s at index %s" local ERROR_NON_LIST = "Please pass a list of promises to %s" local ERROR_NON_FUNCTION = "Please pass a handler function to %s!" +local MODE_KEY_METATABLE = { + __mode = "k"; +} + local RunService = game:GetService("RunService") --[[ @@ -130,9 +134,7 @@ function Promise.new(callback, parent) -- cancellation propagation. _parent = parent, - _consumers = setmetatable({}, { - __mode = "k"; - }), + _consumers = setmetatable({}, MODE_KEY_METATABLE), } if parent and parent._status == Promise.Status.Started then