Avoid reallocating another table for the _consumers() metatable, leading to a 5%-10% speed up of the trivial Promise.new(function() end) case

This commit is contained in:
James Onnen 2020-03-29 03:35:15 -07:00
parent f0fd3020fd
commit ffd4cd94a1
No known key found for this signature in database
GPG key ID: F629FA7DBA28E038

View file

@ -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