View Single Post
09-25-16, 05:53 AM   #18
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Originally Posted by Kagura View Post
I would also urge you to do performance and memory checking on the generated code before you judge it
Originally Posted by Kagura View Post
Code:
  do
    local WindowWithTitle = __Modules.k.__default__
    local SmallButton = __Modules.m.__default__
    local Text = __Modules.i.__default__
    local UI = __Modules.d.__default__
    local Component = __Modules.d.Component
    local Panel = __Modules.n.__default__
    local Test = Component:extend({ events = { "UNIT_AURA" } })

    Test.__class = 'Test'


    function Test:Test__UNIT_AURA(...)
      prettyPrint("Components\Test.js:13", "Someone gained aura!", ...)
    end
    Test.UNIT_AURA = Test.Test__UNIT_AURA

    function Test:Test__ok()
      prettyPrint("Components\Test.js:17", "You pressed ok")
    end
    Test.ok = Test.Test__ok

    function Test:Test__cancel()
      prettyPrint("Components\Test.js:21", "You pressed cancel")
    end
    Test.cancel = Test.Test__cancel

    function Test:Test__render()
      return { WindowWithTitle, { movable = true, title = "Broxxigar the red", width = 512, height = 512, anchors = { { "CENTER" } } }, { Text, { anchors = { { "TOPLEFT" }, { "BOTTOMRIGHT", "parent", "RIGHT" } }, align = "LEFT", vAlign = "TOP" }, "Even for an orc, Broxigar the Red was obsessed with honor and felt he had lost his by living. While he served the Horde with distinction all his life, his true shame came from an action he took long after the Blood Curse had lifted and Thrall has assumed the mantle of Warchief. During the Third War, as the Horde struggled to prevent the demonic army of the Burning Legion from claiming Mount Hyjal as their own, Broxigar led a force of orc warriors in the defense of a vital choke point that would give the Legion their path. Rather than allow the demons to proceed, the orcs stood and died. All of them. All of them save Broxigar." }, { SmallButton, { anchors = { { "BOTTOMLEFT" } }, onClick = function ()
        self:ok()
      end }, { Text, { anchors = "*" }, "OK" } }, { SmallButton, { anchors = { { "BOTTOMRIGHT" } }, onClick = function ()
        self:cancel()
      end }, { Text, { anchors = "*" }, "Cancel" } } }
    end
    Test.render = Test.Test__render

    __Modules.o = __Modules.o or {}
    __Modules.o.__default__ = Test
  end
Without the full code, it's impossible to run any tests.
Test.lua:2: attempt to index global '__Modules' (a nil value)


Many of us here have already done research on the backend of Lua and know how everything runs on C-side. We know what to avoid to make sure our code is solid, clean, and smooth running. We aren't picking on your code just because we think it's ugly. We have years, some of us even decades of experience in Lua specifically that gives us insight on how the computer is going to approach it.

If you're interested in trimming down your CPU usage, the most expensive Lua operations are function calls followed by table indexing. Indexing operations are what surprise a lot of people because of how much they can stack up. Accessing a global is an indexing operation on Lua's environment table. Metatables add at least two indexing operations each whenever they need to be accessed if __index is another table. If it's a function, then it's an indexing operation plus the function call.

You should also keep an eye on memory usage. Garbage collection cycles are notorious for causing large amounts of framerate drops. Because of this, avoid creating dynamic tables and functions and releasing them very often.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 09-25-16 at 06:19 AM.
  Reply With Quote