New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core: use ColorMixin for colors #604
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
If you want to update everything else to use :GetRGB() and whatnot that's up to you, but it'll eventually be something we'll want to do. This probably also involves updating the color-related APIs oUF exposes, but they can probably be left alone unless there are performance reasons to update them. |
Used following code for a perf benchmark where package.path = package.path .. ';./?.lua'
require('color')
local function benchmark(times, name, f, ...)
local start = os.clock()
for i = 1, times do
f(...)
end
local elapsed = (os.clock() - start)
print(('%16s: %9.3f ms'):format(name, elapsed * 1e4))
end
local r, g, b = 0.1, 0.4, 0.8
local color = CreateColor(r, g, b)
color[1] = r
color[2] = g
color[3] = b
color.atlas = 'some-atlas'
local color2 = { r, g, b, atlas = 'some-atlas' }
local function callRGB(color)
local r, g, b = color:GetRGB()
end
local function callUnpack(color)
local r, g, b = unpack(color)
end
local function getByIndex(color)
local r, g, b = color[1], color[2], color[3]
end
local function getByName(color)
local r, g, b = color.r, color.g, color.b
end
benchmark(1e6, 'color:getRGB()', callRGB, color)
benchmark(1e6, 'unpack(mixin)', callUnpack, color)
benchmark(1e6, 'index mixin', getByIndex, color)
benchmark(1e6, 'name mixin', getByName, color)
benchmark(1e6, 'unpack(simple)', callUnpack, color2)
benchmark(1e6, 'index simple', getByIndex, color2)
benchmark(1e6, 'name simple', getByName, color2) Results:
So I kept the direct table access instead of calling |
This is in preparation to ditch the array part we added to ColorMixin for backwards compatibility. I keep the direct tble access instead of calling color:getRGB() for perfomance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Closes #590
No BC breaks. I'll switch elements and stuff if you want this. Just left them in for now to demonstrate BC.