Import global functions and constants for enhanced performance

This is better for performance because these then don't need to be reevaluated every time they are called.

When encountering an unqualified function or constant reference, PHP will first try to locate a symbol in the current namespace by that name, and then fall back to the global namespace.
This short-circuits the check, which has substantial performance effects in some cases - in particular, ord(), chr() and strlen() show ~1500x faster calls when they are fully qualified.

However, this doesn't mean that PM is getting a massive amount faster. In real world terms, this translates to about 10-15% performance improvement.
But before anyone gets excited, you should know that the CodeOptimizer in the PreProcessor repo has been applying fully-qualified symbol optimizations to Jenkins builds for years, which is one of the reasons why Jenkins builds have better performance than home-built or source installations.
We're choosing to do this for the sake of future SafePHP integration and also to be able to get rid of the buggy CodeOptimizer, so that phar and source are more consistent.
This commit is contained in:
Dylan K. Taylor
2019-01-04 20:43:15 +00:00
parent 0bacf51729
commit 4b9a142a5d
250 changed files with 1314 additions and 45 deletions

View File

@ -25,6 +25,15 @@ namespace pocketmine\scheduler;
use pocketmine\Server;
use pocketmine\utils\Utils;
use function array_keys;
use function assert;
use function count;
use function get_class;
use function spl_object_hash;
use function time;
use const PHP_INT_MAX;
use const PTHREADS_INHERIT_CONSTANTS;
use const PTHREADS_INHERIT_INI;
/**
* Manages general-purpose worker threads used for processing asynchronous tasks, and the tasks submitted to those

View File

@ -25,6 +25,9 @@ namespace pocketmine\scheduler;
use pocketmine\Collectable;
use pocketmine\Server;
use function is_scalar;
use function serialize;
use function unserialize;
/**
* Class used to run async tasks in other threads.

View File

@ -26,6 +26,10 @@ namespace pocketmine\scheduler;
use pocketmine\utils\MainLogger;
use pocketmine\utils\Utils;
use pocketmine\Worker;
use function error_reporting;
use function gc_enable;
use function ini_set;
use function set_error_handler;
class AsyncWorker extends Worker{
/** @var mixed[] */

View File

@ -25,6 +25,8 @@ namespace pocketmine\scheduler;
use pocketmine\utils\Internet;
use pocketmine\utils\InternetException;
use function serialize;
use function unserialize;
/**
* Executes a consecutive list of cURL operations.

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\scheduler;
use pocketmine\MemoryManager;
use const DIRECTORY_SEPARATOR;
/**
* Task used to dump memory from AsyncWorkers

View File

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace pocketmine\scheduler;
use function file_put_contents;
class FileWriteTask extends AsyncTask{
/** @var string */

View File

@ -23,6 +23,9 @@ declare(strict_types=1);
namespace pocketmine\scheduler;
use function gc_collect_cycles;
use function gc_enable;
class GarbageCollectionTask extends AsyncTask{
public function onRun(){

View File

@ -29,6 +29,14 @@ use pocketmine\utils\Internet;
use pocketmine\utils\Utils;
use pocketmine\utils\UUID;
use pocketmine\utils\VersionString;
use function array_values;
use function count;
use function json_encode;
use function md5;
use function microtime;
use function php_uname;
use function strlen;
use const PHP_VERSION;
class SendUsageTask extends AsyncTask{