Quote Originally Posted by ZorbaTHut View Post
Quote Originally Posted by jca View Post
Here's an extremely simple and easily reproduced sample of the problem.
Aha, just what I needed So, some performance numbers, and note that these are all pretty arbitrary (it's my development box running development code with whatever detail settings I happen to be using): First, I changed the update to every frame, not every 1/2 second, just to get a better sense of the impact. The current code uses about 80% of the CPU to do 10 updates per second. There are some pretty significant improvements that can be made, and those will be showing up in a hotpatch. Those bring it down to 45% of the CPU to do 35 updates per second. That said, your code is rather inefficient in the first place. Take this function, for example:
Code:
 local function _oldlayoutBoxes() 	-- arranges the boxes in a grid which moves 10 pixels each update 	x = x + 20 	y = y + 20 	 	local anchor 	 	for i, box in ipairs(boxes) do 		if (i == 1) then 			box:SetPoint("TOPLEFT", UIParent, "TOPLEFT", x, y) 		elseif (i == 21) then 			box:SetPoint("TOPLEFT", boxes[1], "BOTTOMLEFT") 		elseif (i == 41) then 			box:SetPoint("TOPLEFT", boxes[21], "BOTTOMLEFT") 		elseif (i == 61) then 			box:SetPoint("TOPLEFT", boxes[41], "BOTTOMLEFT") 		else 			box:SetPoint("LEFTCENTER", anchor, "RIGHTCENTER") 		end 		 		anchor = box 	end 		 	if (x > 800) then x = 100 end 	if (y > 800) then y = 100 end end
:SetPoint() creates a persistent constraint - there's no reason to call it over and over with the same parameters. Renaming this function to "_createLayout", calling it in _loaded(), and creating a new function "_layoutBoxes" like this:
Code:
 local function _layoutBoxes() 	-- arranges the boxes in a grid which moves 10 pixels each update 	x = x + 20 	y = y + 20 	 	local anchor 	 	boxes[1]:SetPoint("TOPLEFT", UIParent, "TOPLEFT", x, y) 		 	if (x > 800) then x = 100 end 	if (y > 800) then y = 100 end end
results in 20% CPU usage for 45 updates per second. At this point, the largest CPU drain is setting the text - recalculating the text bounds can be a bit slow. For comparison, disabling the :SetText() in _updateBox brings it all the way down to 8% CPU usage for 45 updates per second, although by now the addon system is eating 4% of the CPU as well. We'll probably be improving that in the future, but most of the text shown likely doesn't change every frame in a realistic situation. Anyway, we'll hopefully get our performance issues taken care of soon, and there's some suggestions on how to speed things up a lot.
Jump to post...