We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25663 MODX Staff
    • 12,272 Posts
    Raymond/Jason,

    For the sake of keeping the core lean and mean, I say we implement that type of functionality as a plugin. That way, no extra perceived overhead if the feature isn't used. wink
      Ryan Thrash, MODX Co-Founder
      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
      • 32963
      • 1,732 Posts
      Raymond/Jason,

      For the sake of keeping the core lean and mean, I say we implement that type of functionality as a plugin. That way, no extra perceived overhead if the feature isn't used. wink

      Well the truth is that such features would have to wait until we have modules working as it would require some UI inside the manager. A module can be linked to a collection of snippets, plugins, tv, documents, etc in order provide the user with a complete package.
        xWisdom
        www.xwisdomhtml.com
        The fear of the Lord is the beginning of wisdom:
        MODx Co-Founder - Create and do more with less.
        • 34162
        • 1 Posts

        Well in a nut shell...

        Plugins are only executed when needed. Take for example the OnWebPagePrerender event is invoked everytime a page is loaded but it will only execute those plugins that are listening to that event. In other words if there are no plugins listening to the OnWebPagePrerender event then nothing is executed and the system continues as normal.

        Ok, I'm good with the execution. However, are they still loaded into memory? In other words, if I have 25 plugins related to something like document editing and I'm instead working on roles or users, are these still loaded into memory, even if they aren't going to be executed?

        Same thing with front end plugins: are the manager plugins still getting loaded even when the front end runs and you aren't in the manager? What about vice verse?

        Execution to me isn't that big a deal. Loading segments of code that aren't used, though, is huge to me.
          • 32963
          • 1,732 Posts

          Well in a nut shell...

          Plugins are only executed when needed. Take for example the OnWebPagePrerender event is invoked everytime a page is loaded but it will only execute those plugins that are listening to that event. In other words if there are no plugins listening to the OnWebPagePrerender event then nothing is executed and the system continues as normal.

          Ok, I'm good with the execution. However, are they still loaded into memory? In other words, if I have 25 plugins related to something like document editing and I'm instead working on roles or users, are these still loaded into memory, even if they aren't going to be executed?

          Same thing with front end plugins: are the manager plugins still getting loaded even when the front end runs and you aren't in the manager? What about vice verse?

          Execution to me isn't that big a deal. Loading segments of code that aren't used, though, is huge to me.

          And the answer is... Yes! Currently they are loaded into memory the same way snippets are loaded.

          Note I said currently. In future versions this will be changed to allow separate cache pages like what you had recommended smiley

          Edited
          But I think by using separate cache files we might see little performance hit when executing lots of plugin at any one time, correct?
          Overal I guess separate cache file would be best for memory concerns but might not be for execution.

          What do you think?
            xWisdom
            www.xwisdomhtml.com
            The fear of the Lord is the beginning of wisdom:
            MODx Co-Founder - Create and do more with less.
            • 32963
            • 1,732 Posts
            Currently the system is very extensible with the introduction of the new system events. We could make a plugin manage the cache services or we could rewrite the cache services to group the plugin cache files together!

            That's it!

            In other words if the plugins are grouped then that would have solve the file include performance problem! All plugins that listen to EventA are cached in fileA and so on.

            So if you have 100 plugins listening to EventA then all those plugins are loaded into memory. One file vs 100 files.

            Got it? - Intelli-Cache smiley
              xWisdom
              www.xwisdomhtml.com
              The fear of the Lord is the beginning of wisdom:
              MODx Co-Founder - Create and do more with less.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Hm. Reminds me of when I discovered that QuickBasic loaded the entire graphics library into your pcode if you used a single graphics function...like "cls". There was a third-party "patch" for it that contained libraries that only loaded the function called, but it wasn't free, and by the time I learned about it I was using a second-hand Borland multi-compiler package, and a bunch of shareware stuff. I loved BasicBasic; it had libraries for creating Windows GUI widgets using the Windows API. You had to code them by hand; this was about a year before VB first came out.

              So, I've never quite understood why the system can't gather up an array of snippets etc any given page uses, and only get those from the database when the page is being generated? I don't see an advantage to having it in the filesystem; it's six of one and half a dozen of the other to actually get the snippet code when generating the page; why go to the trouble and overhead of writing more stuff to the database or filesystem? There could be another table in the database for object dependencies; this could be used in a complex join query statement to grab any snippets or what-have-you that the objects directly called for by the document need at the same time as getting the object itself. Ok. Say that ten times fast.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 34162
                • 1 Posts
                I don't see an advantage to having it in the filesystem; it's six of one and half a dozen of the other to actually get the snippet code when generating the page; why go to the trouble and overhead of writing more stuff to the database or filesystem?

                I'm propping my eyes open with toothpicks at the moment, but the core difference is that to run code from the DB you have to basically fork a process using eval() which is considerably slower than just running code from a include() or require() command. Especially if you have multiple code bits to be executed, the delays in eval()s add up.

                Or, as they even say in the manual at PHP.net:
                If eval() is the answer, you're almost certainly asking the
                wrong question. -- Rasmus Lerdorf, BDFL of PHP

                Eval() is a worst case solution when you absolutely, positively cannot find a better way. *Especially* on any system running 4.x-- the Zend engine changes the PHP to a binary structure at the start of the PHP file, prior to parsing it. Every time eval() is called, however, it has to reactivate the parsing procedure and convert the eval()'d code into a binary format.

                So, in essence, if you eval() code, it takes as long as calling a new php page with the same code inside. Or, put another way: a single PHP file plus four eval() statements will take as long as FIVE PHP files being called individually.

                Does that help?
                  • 32963
                  • 1,732 Posts

                  So, in essence, if you eval() code, it takes as long as calling a new php page with the same code inside. Or, put another way: a single PHP file plus four eval() statements will take as long as FIVE PHP files being called individually.

                  Does that help?


                  From my little test I think you will run into problems when you start including snippets and plugins with the same function name:

                  Fatal error: Cannot redeclare tester()

                  Where tester is used in to separate include files.


                  From what I see we would have to either use unique function names or continue to use eval(). IMO eval() seems to be doing a great job thus far. 100 plugins executed within a fraction of a section! Now most sites will not be running that many plugins at any given point in time.
                    xWisdom
                    www.xwisdomhtml.com
                    The fear of the Lord is the beginning of wisdom:
                    MODx Co-Founder - Create and do more with less.
                    • 34162
                    • 1 Posts

                    From what I see we would have to either use unique function names or continue to use eval(). IMO eval() seems to be doing a great job thus far. 100 plugins executed within a fraction of a section! Now most sites will not be running that many plugins at any given point in time.

                    Unfortunately, it doesn't work for my purposes at all using the current system.

                    I'll give it some more thought, but I'm beginning to really think I may just need to do a high performance side project. I served over a million dynamically created pages *in a single day* yesterday and did it using less than 20% of my server's resources.

                    There's no earthly way I could do that with the system as it is now, but correcting the performance issues is going to require a considerable amount of reworking.

                    I'll do some more thinking. smiley