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,8 @@ declare(strict_types=1);
namespace pocketmine\utils;
use function count;
class Color{
/** @var int */

View File

@ -23,6 +23,37 @@ declare(strict_types=1);
namespace pocketmine\utils;
use function array_change_key_case;
use function array_keys;
use function array_pop;
use function array_shift;
use function basename;
use function count;
use function date;
use function explode;
use function file_exists;
use function file_get_contents;
use function file_put_contents;
use function implode;
use function is_array;
use function is_bool;
use function json_decode;
use function json_encode;
use function preg_match_all;
use function preg_replace;
use function serialize;
use function str_replace;
use function strlen;
use function strtolower;
use function substr;
use function trim;
use function unserialize;
use function yaml_emit;
use function yaml_parse;
use const CASE_LOWER;
use const JSON_BIGINT_AS_STRING;
use const JSON_PRETTY_PRINT;
/**
* Config Class for simple config manipulation of multiple formats.
*/

View File

@ -23,6 +23,35 @@ declare(strict_types=1);
namespace pocketmine\utils;
use function array_merge;
use function curl_close;
use function curl_error;
use function curl_exec;
use function curl_getinfo;
use function curl_init;
use function curl_setopt_array;
use function explode;
use function preg_match;
use function strip_tags;
use function strtolower;
use function substr;
use function trim;
use const CURLINFO_HEADER_SIZE;
use const CURLINFO_HTTP_CODE;
use const CURLOPT_AUTOREFERER;
use const CURLOPT_CONNECTTIMEOUT_MS;
use const CURLOPT_FOLLOWLOCATION;
use const CURLOPT_FORBID_REUSE;
use const CURLOPT_FRESH_CONNECT;
use const CURLOPT_HEADER;
use const CURLOPT_HTTPHEADER;
use const CURLOPT_POST;
use const CURLOPT_POSTFIELDS;
use const CURLOPT_RETURNTRANSFER;
use const CURLOPT_SSL_VERIFYHOST;
use const CURLOPT_SSL_VERIFYPEER;
use const CURLOPT_TIMEOUT_MS;
class Internet{
public static $ip = false;
public static $online = true;

View File

@ -26,6 +26,33 @@ namespace pocketmine\utils;
use LogLevel;
use pocketmine\Thread;
use pocketmine\Worker;
use function fclose;
use function fopen;
use function fwrite;
use function get_class;
use function is_resource;
use function preg_replace;
use function sprintf;
use function time;
use function touch;
use function trim;
use const E_COMPILE_ERROR;
use const E_COMPILE_WARNING;
use const E_CORE_ERROR;
use const E_CORE_WARNING;
use const E_DEPRECATED;
use const E_ERROR;
use const E_NOTICE;
use const E_PARSE;
use const E_RECOVERABLE_ERROR;
use const E_STRICT;
use const E_USER_DEPRECATED;
use const E_USER_ERROR;
use const E_USER_NOTICE;
use const E_USER_WARNING;
use const E_WARNING;
use const PHP_EOL;
use const PTHREADS_INHERIT_NONE;
class MainLogger extends \AttachableThreadedLogger{

View File

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace pocketmine\utils;
use function time;
/**
* XorShift128Engine Random Number Noise, used for fast seeded values
* Most of the code in this class was adapted from the XorShift128Engine in the php-random library.

View File

@ -24,6 +24,8 @@ declare(strict_types=1);
namespace pocketmine\utils;
use pocketmine\Thread;
use function getmypid;
use function time;
class ServerKiller extends Thread{

View File

@ -23,6 +23,14 @@ declare(strict_types=1);
namespace pocketmine\utils;
use function fclose;
use function fopen;
use function function_exists;
use function getenv;
use function getopt;
use function is_array;
use function stream_isatty;
abstract class Terminal{
public static $FORMAT_BOLD = "";
public static $FORMAT_OBFUSCATED = "";

View File

@ -23,6 +23,17 @@ declare(strict_types=1);
namespace pocketmine\utils;
use function is_array;
use function json_encode;
use function preg_quote;
use function preg_replace;
use function preg_split;
use function str_repeat;
use function str_replace;
use const JSON_UNESCAPED_SLASHES;
use const PREG_SPLIT_DELIM_CAPTURE;
use const PREG_SPLIT_NO_EMPTY;
/**
* Class used to handle Minecraft chat format, and convert it to other formats like HTML
*/

View File

@ -23,6 +23,27 @@ declare(strict_types=1);
namespace pocketmine\utils;
use function abs;
use function date_default_timezone_set;
use function date_parse;
use function exec;
use function file_exists;
use function file_get_contents;
use function implode;
use function ini_get;
use function ini_set;
use function is_link;
use function json_decode;
use function parse_ini_file;
use function preg_match;
use function readlink;
use function str_replace;
use function strpos;
use function substr;
use function timezone_abbreviations_list;
use function timezone_name_from_abbr;
use function trim;
abstract class Timezone{
public static function get() : string{

View File

@ -23,6 +23,19 @@ declare(strict_types=1);
namespace pocketmine\utils;
use function bin2hex;
use function getmypid;
use function getmyuid;
use function hash;
use function hex2bin;
use function implode;
use function mt_rand;
use function str_replace;
use function strlen;
use function substr;
use function time;
use function trim;
class UUID{
private $parts = [0, 0, 0, 0];

View File

@ -29,6 +29,70 @@ namespace pocketmine\utils;
use DaveRandom\CallbackValidator\CallbackType;
use pocketmine\ThreadManager;
use function array_combine;
use function array_map;
use function array_reverse;
use function array_values;
use function base64_decode;
use function bin2hex;
use function chunk_split;
use function count;
use function debug_zval_dump;
use function dechex;
use function error_reporting;
use function exec;
use function explode;
use function fclose;
use function file;
use function file_exists;
use function file_get_contents;
use function function_exists;
use function get_class;
use function get_current_user;
use function get_loaded_extensions;
use function getenv;
use function gettype;
use function hexdec;
use function implode;
use function is_array;
use function is_object;
use function is_readable;
use function is_string;
use function json_decode;
use function memory_get_usage;
use function ob_end_clean;
use function ob_get_contents;
use function ob_start;
use function ord;
use function php_uname;
use function phpversion;
use function posix_kill;
use function preg_grep;
use function preg_match;
use function preg_match_all;
use function preg_replace;
use function proc_close;
use function proc_open;
use function sha1;
use function spl_object_hash;
use function str_pad;
use function str_replace;
use function str_split;
use function stream_get_contents;
use function stripos;
use function strlen;
use function strpos;
use function strtolower;
use function strval;
use function sys_get_temp_dir;
use function trim;
use function xdebug_get_function_stack;
use const PHP_EOL;
use const PHP_INT_MAX;
use const PHP_INT_SIZE;
use const PHP_MAXPATHLEN;
use const STR_PAD_LEFT;
use const STR_PAD_RIGHT;
/**
* Big collection of functions

View File

@ -24,6 +24,9 @@ declare(strict_types=1);
namespace pocketmine\utils;
use function count;
use function preg_match;
/**
* Manages PocketMine-MP version strings, and compares them
*/