• Resolved jmslbam

    (@jmslbam)


    I used https://nintechnet.com/codeprofiler/ to analyse a site and noticed that this plugin had quite a big overhead compared to what functionality it brings to the table.

    The analyser gave this feedback:

    Why does Code Profiler warn me that I have multiple plugins using Composer?

    Composer, a tool for dependency management in PHP, is included in many popular plugins and themes. It is used to autoload PHP classes.
    Code Profiler will inform you if two or more activated plugins use it because you will need to take it into consideration when reading and interpreting the results. Let’s take an example:
    Assuming you have four plugins, #1, #2, #3 and #4. Both plugins #1 and #4 include and require Composer. WordPress will start and load plugin #1, which will run an instance of Composer to load its classes. Immediately after, WordPress will load plugins #2 and #3. Then, it will load plugin #4, which too will need to load its classes. However, plugin #4 will not start a new instance of Composer but, instead, will rely on the one from plugin #1 to load its own classes.
    As a result, the execution time of plugin #1 will increase (its instance of Composer is used to load classes for plugin #4 too), while the execution time of plugin #4 will decrease (it doesn’t need to start a new instance of Composer). Therefore, if you have a dozen or more plugins using Composer, it is important to take into consideration that the execution time of plugin #1 may be much higher than other plugins.
    Also, assuming you are a developer and just want to profile a plugin that you wrote and that includes Composer, you will need to disable any other plugin using Composer in order to get the most accurate results for your plugin only.y does Code Profiler warn me that I have multiple plugins using Composer?

    Here are the result by just using an simple require.php which include the 3 files needed instead of using Composer.

    Before:

    After

    It’s not much, but every performance tweak helps, hope you consider this tweak or have a little custom autoloader.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Arno Welzel

    (@awelzel)

    Please do not use tools if you can’t interpret the results properly – thank you!

    My plugin does not use Composer packages at runtime for only to build the assets in build.php (also see the Makefile and comment for developers how to build the assets when changing any of the source files). Using Composer packages at runtime in WordPress would be a very bad idea since autoloaders used by different plugins or themes at the same time can and will cause a conflict.

    • This reply was modified 2 months, 2 weeks ago by Arno Welzel.
    Plugin Author Arno Welzel

    (@awelzel)

    I will provide an update which does not use the autoloader at runtime, since it is not needed.

    Plugin Author Arno Welzel

    (@awelzel)

    Version 5.7.4 will not use the autoloader any longer at runtime.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.