mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 19:02:59 +00:00
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:
@ -23,6 +23,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\plugin;
|
||||
|
||||
use function is_file;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
|
||||
/**
|
||||
* Handles different types of plugins
|
||||
*/
|
||||
|
@ -29,6 +29,21 @@ use pocketmine\command\PluginIdentifiableCommand;
|
||||
use pocketmine\scheduler\TaskScheduler;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\Config;
|
||||
use function dirname;
|
||||
use function fclose;
|
||||
use function file_exists;
|
||||
use function fopen;
|
||||
use function is_dir;
|
||||
use function mkdir;
|
||||
use function rtrim;
|
||||
use function str_replace;
|
||||
use function stream_copy_to_stream;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function strtolower;
|
||||
use function substr;
|
||||
use function trim;
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
|
||||
abstract class PluginBase implements Plugin{
|
||||
|
||||
|
@ -24,6 +24,20 @@ declare(strict_types=1);
|
||||
namespace pocketmine\plugin;
|
||||
|
||||
use pocketmine\permission\Permission;
|
||||
use function array_map;
|
||||
use function array_values;
|
||||
use function constant;
|
||||
use function defined;
|
||||
use function extension_loaded;
|
||||
use function is_array;
|
||||
use function phpversion;
|
||||
use function preg_match;
|
||||
use function str_replace;
|
||||
use function stripos;
|
||||
use function strlen;
|
||||
use function strtoupper;
|
||||
use function substr;
|
||||
use function version_compare;
|
||||
|
||||
class PluginDescription{
|
||||
private $map;
|
||||
@ -81,8 +95,8 @@ class PluginDescription{
|
||||
throw new PluginException("Invalid PluginDescription main, cannot start within the PocketMine namespace");
|
||||
}
|
||||
|
||||
$this->api = array_map("strval", (array) ($plugin["api"] ?? []));
|
||||
$this->compatibleMcpeProtocols = array_map("intval", (array) ($plugin["mcpe-protocol"] ?? []));
|
||||
$this->api = array_map("\strval", (array) ($plugin["api"] ?? []));
|
||||
$this->compatibleMcpeProtocols = array_map("\intval", (array) ($plugin["mcpe-protocol"] ?? []));
|
||||
|
||||
if(isset($plugin["commands"]) and is_array($plugin["commands"])){
|
||||
$this->commands = $plugin["commands"];
|
||||
|
@ -25,6 +25,7 @@ namespace pocketmine\plugin;
|
||||
|
||||
use LogLevel;
|
||||
use pocketmine\Server;
|
||||
use function spl_object_hash;
|
||||
|
||||
class PluginLogger implements \AttachableLogger{
|
||||
|
||||
|
@ -38,6 +38,29 @@ use pocketmine\permission\PermissionManager;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\timings\TimingsHandler;
|
||||
use pocketmine\utils\Utils;
|
||||
use function array_intersect;
|
||||
use function array_map;
|
||||
use function array_pad;
|
||||
use function class_exists;
|
||||
use function count;
|
||||
use function dirname;
|
||||
use function explode;
|
||||
use function file_exists;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function implode;
|
||||
use function is_a;
|
||||
use function is_array;
|
||||
use function is_bool;
|
||||
use function is_dir;
|
||||
use function is_string;
|
||||
use function is_subclass_of;
|
||||
use function mkdir;
|
||||
use function stripos;
|
||||
use function strpos;
|
||||
use function strtolower;
|
||||
use function strtoupper;
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* Manages all the plugins
|
||||
@ -362,7 +385,7 @@ class PluginManager{
|
||||
public function isCompatibleApi(string ...$versions) : bool{
|
||||
$serverString = $this->server->getApiVersion();
|
||||
$serverApi = array_pad(explode("-", $serverString), 2, "");
|
||||
$serverNumbers = array_map("intval", explode(".", $serverApi[0]));
|
||||
$serverNumbers = array_map("\intval", explode(".", $serverApi[0]));
|
||||
|
||||
foreach($versions as $version){
|
||||
//Format: majorVersion.minorVersion.patch (3.0.0)
|
||||
@ -374,7 +397,7 @@ class PluginManager{
|
||||
continue;
|
||||
}
|
||||
|
||||
$pluginNumbers = array_map("intval", array_pad(explode(".", $pluginApi[0]), 3, "0")); //plugins might specify API like "3.0" or "3"
|
||||
$pluginNumbers = array_map("\intval", array_pad(explode(".", $pluginApi[0]), 3, "0")); //plugins might specify API like "3.0" or "3"
|
||||
|
||||
if($pluginNumbers[0] !== $serverNumbers[0]){ //Completely different API version
|
||||
continue;
|
||||
|
@ -23,6 +23,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\plugin;
|
||||
|
||||
use function file;
|
||||
use function is_file;
|
||||
use function preg_match;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
use function trim;
|
||||
use const FILE_IGNORE_NEW_LINES;
|
||||
use const FILE_SKIP_EMPTY_LINES;
|
||||
|
||||
/**
|
||||
* Simple script loader, not for plugin development
|
||||
* For an example see https://gist.github.com/shoghicp/516105d470cf7d140757
|
||||
|
Reference in New Issue
Block a user