Skip to content

phpseclib Mcrypt performance slow #30556

@MichaelThessel

Description

@MichaelThessel

Description (*)

Support OpenSSL for encryption.

Expected behavior (*)

While profiling a M2 site I noticed that phpseclib is always the single slowest component. In some cases I see 700ms of my page load time attributed to it. At first I thought that this is an issue with my profiler but I have since confirmed that with (New Relic, xdebug and xhprof).

20201019_150852
20201019_151402

I had a look at the code and in Magento\Framework\Encryption\Encryptor::getCrypt I see that Mcrypt is hardcoded.


  | #0  Magento\Framework\Encryption\Encryptor->getCrypt() called at [/data/src/m2/vendor/magento/framework/Encryption/Encryptor.php:450]
  | #1  Magento\Framework\Encryption\Encryptor->decrypt() called at [/data/src/m2/vendor/magento/module-config/App/Config/Type/System.php:252]
  | #2  Magento\Config\App\Config\Type\System->Magento\Config\App\Config\Type\{closure}() called at [/data/src/m2/vendor/magento/framework/Cache/LockGuardedCacheLoader.php:84]
  | #3  Magento\Framework\Cache\LockGuardedCacheLoader->lockedLoadData() called at [/data/src/m2/vendor/magento/module-config/App/Config/Type/System.php:261]
  | #4  Magento\Config\App\Config\Type\System->loadDefaultScopeData() called at [/data/src/m2/vendor/magento/module-config/App/Config/Type/System.php:195]
  | #5  Magento\Config\App\Config\Type\System->getWithParts() called at [/data/src/m2/vendor/magento/module-config/App/Config/Type/System.php:169]
  | #6  Magento\Config\App\Config\Type\System->get() called at [/data/src/m2/vendor/magento/framework/App/Config.php:132]
  | #7  Magento\Framework\App\Config->get() called at [/data/src/m2/vendor/magento/module-backend/App/Config.php:51]
  | #8  Magento\Backend\App\Config->getValue() called at [/data/src/m2/vendor/magento/module-backend/App/Area/FrontNameResolver.php:109]
  | #9  Magento\Backend\App\Area\FrontNameResolver->getFrontName() called at [/data/src/m2/vendor/magento/module-backend/Helper/Data.php:209]
  | #10 Magento\Backend\Helper\Data->getAreaFrontName() called at [/data/src/m2/vendor/magento/module-backend/App/Request/PathInfoProcessor.php:50]
  | #11 Magento\Backend\App\Request\PathInfoProcessor->process() called at [/data/src/m2/generated/code/Magento/Backend/App/Request/PathInfoProcessor/Proxy.php:95]
  | #12 Magento\Backend\App\Request\PathInfoProcessor\Proxy->process() called at [/data/src/m2/vendor/magento/framework/App/Request/Http.php:147]
  | #13 Magento\Framework\App\Request\Http->getOriginalPathInfo() called at [/data/src/m2/vendor/magento/framework/App/Request/Http.php:162]
  | #14 Magento\Framework\App\Request\Http->getPathInfo() called at [/data/src/m2/vendor/magento/framework/App/Request/Http.php:217]
  | #15 Magento\Framework\App\Request\Http->getFrontName() called at [/data/src/m2/vendor/magento/framework/App/Http.php:111]
  | #16 Magento\Framework\App\Http->launch() called at [/data/src/m2/vendor/magento/framework/App/Bootstrap.php:261]
  | #17 Magento\Framework\App\Bootstrap->run() called at [/data/src/m2/pub/index.php:40]

This leads to the problem that if you don't have https://pecl.php.net/package/mcrypt installed this is super slow because it does the en/decryption in PHP using phpseclib. The mcrypt PHP lib is deprecated though and not supposed to be used anymore. I installed it for testing purposes and sure enough the decryption is more than 100x faster.

20201019_152827

As OpenSSL is a system requirement for M2 (https://devdocs.magento.com/guides/v2.4/install-gde/system-requirements-tech.html) why don't we use it instead of Mcrypt?

Benefits

Make M2 much faster

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: ready for devReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S2Major restrictions or short-term circumventions are required until a fix is available.Triage: Performancefeature request

    Type

    No type

    Projects

    Status

    Ready for Grooming

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions