HISE Logo Forum
    • Categories
    • Register
    • Login

    Performance overhead of Global variables vs. Const Var

    Scheduled Pinned Locked Moved Scripting
    7 Posts 3 Posters 313 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Casey KolbC
      Casey Kolb
      last edited by

      Just out of curiosity, does anyone know if there's a big difference in performance between accessing Globals.someComponent and const var someComponent? I'm running a few benchmark tests but it's a bit hard to tell. It seems like const var might be slightly faster.

      Casey Kolb
      Founder & CEO of Lunacy Audio
      Composer | Producer | Software Developer

      1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart
        last edited by

        Globals are about as fast as normal vars but there are some optimizations possible with const vars that increase the performance (eg. API calls on a const object are resolved at compile time)

        1 Reply Last reply Reply Quote 0
        • d.healeyD
          d.healey
          last edited by

          Globals. someComponent sounds like debugging heaven :)

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

          1 Reply Last reply Reply Quote 0
          • Christoph HartC
            Christoph Hart
            last edited by

            Ah yes, I oversaw that. Nonononono ;)

            1 Reply Last reply Reply Quote 0
            • Casey KolbC
              Casey Kolb
              last edited by Casey Kolb

              Uh oh, have I made a grave error? haha. A lot of my components are stored in Global variables. Poor design choice I know. Probably need to do some major refactoring.

              Casey Kolb
              Founder & CEO of Lunacy Audio
              Composer | Producer | Software Developer

              1 Reply Last reply Reply Quote 0
              • Christoph HartC
                Christoph Hart
                last edited by

                The problem with storing UI elements in global variables is that you transfer the ownership of UI elements out of the ScriptProcessor where they have been defined, which might result in their lifetime exceeding their parent processor and this might cause crashes (most likely when you close a plugin).

                Why do you store them in Globals?

                Casey KolbC 1 Reply Last reply Reply Quote 1
                • Casey KolbC
                  Casey Kolb @Christoph Hart
                  last edited by Casey Kolb

                  @Christoph-Hart I was originally approaching the Globals container like a React state. This was way back when I started this project and I just continued with that paradigm without realizing how HISE restores its state. However, I totally see the danger here. I'll need to refactor it all.

                  On another note, I'm trying to understand the optimization of the const var. If I store a bunch of UI elements in one const var thisNamespaceUI = {} for clarity, do I get the same compile optimizations as if I were just storing them in individual constant variables? For example, you'd have thisNamespaceUI.panelOne.buttonOne thisNamespaceUI.panelOne.buttonTwo etc.

                  Casey Kolb
                  Founder & CEO of Lunacy Audio
                  Composer | Producer | Software Developer

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post

                  58

                  Online

                  1.7k

                  Users

                  11.7k

                  Topics

                  102.1k

                  Posts