mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +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,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\entity;
|
||||
|
||||
use function max;
|
||||
use function min;
|
||||
|
||||
class Attribute{
|
||||
|
||||
public const ABSORPTION = 0;
|
||||
|
@ -23,6 +23,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\entity;
|
||||
|
||||
use function array_filter;
|
||||
|
||||
class AttributeMap implements \ArrayAccess{
|
||||
/** @var Attribute[] */
|
||||
private $attributes = [];
|
||||
|
@ -25,6 +25,10 @@ namespace pocketmine\entity;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\math\Vector3;
|
||||
use function assert;
|
||||
use function is_float;
|
||||
use function is_int;
|
||||
use function is_string;
|
||||
|
||||
class DataPropertyManager{
|
||||
|
||||
|
@ -29,6 +29,9 @@ use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\event\entity\EntityRegainHealthEvent;
|
||||
use pocketmine\event\player\PlayerExhaustEvent;
|
||||
use pocketmine\utils\Color;
|
||||
use function constant;
|
||||
use function defined;
|
||||
use function strtoupper;
|
||||
|
||||
class Effect{
|
||||
public const SPEED = 1;
|
||||
|
@ -24,6 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\entity;
|
||||
|
||||
use pocketmine\utils\Color;
|
||||
use function max;
|
||||
use const INT32_MAX;
|
||||
|
||||
class EffectInstance{
|
||||
/** @var Effect */
|
||||
|
@ -73,6 +73,23 @@ use pocketmine\plugin\Plugin;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\timings\Timings;
|
||||
use pocketmine\timings\TimingsHandler;
|
||||
use function abs;
|
||||
use function assert;
|
||||
use function cos;
|
||||
use function count;
|
||||
use function current;
|
||||
use function deg2rad;
|
||||
use function floor;
|
||||
use function get_class;
|
||||
use function in_array;
|
||||
use function is_a;
|
||||
use function is_array;
|
||||
use function is_infinite;
|
||||
use function is_nan;
|
||||
use function lcg_value;
|
||||
use function reset;
|
||||
use function sin;
|
||||
use const M_PI_2;
|
||||
|
||||
abstract class Entity extends Location implements Metadatable, EntityIds{
|
||||
|
||||
|
@ -55,6 +55,18 @@ use pocketmine\network\mcpe\protocol\PlayerSkinPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\utils\UUID;
|
||||
use function array_filter;
|
||||
use function array_merge;
|
||||
use function array_rand;
|
||||
use function array_values;
|
||||
use function ceil;
|
||||
use function max;
|
||||
use function min;
|
||||
use function mt_rand;
|
||||
use function random_int;
|
||||
use function strlen;
|
||||
use const INT32_MAX;
|
||||
use const INT32_MIN;
|
||||
|
||||
class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
|
||||
|
@ -51,6 +51,19 @@ use pocketmine\Player;
|
||||
use pocketmine\timings\Timings;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\Color;
|
||||
use function abs;
|
||||
use function array_shift;
|
||||
use function atan2;
|
||||
use function ceil;
|
||||
use function count;
|
||||
use function floor;
|
||||
use function lcg_value;
|
||||
use function max;
|
||||
use function min;
|
||||
use function mt_getrandmax;
|
||||
use function mt_rand;
|
||||
use function sqrt;
|
||||
use const M_PI;
|
||||
|
||||
abstract class Living extends Entity implements Damageable{
|
||||
|
||||
|
@ -23,6 +23,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\entity;
|
||||
|
||||
use function json_decode;
|
||||
use function json_encode;
|
||||
use function strlen;
|
||||
|
||||
class Skin{
|
||||
|
||||
/** @var string */
|
||||
|
@ -29,6 +29,10 @@ use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemFactory;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\mcpe\protocol\EntityEventPacket;
|
||||
use function atan2;
|
||||
use function mt_rand;
|
||||
use function sqrt;
|
||||
use const M_PI;
|
||||
|
||||
class Squid extends WaterAnimal{
|
||||
public const NETWORK_ID = self::SQUID;
|
||||
|
@ -25,6 +25,7 @@ namespace pocketmine\entity;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemFactory;
|
||||
use function mt_rand;
|
||||
|
||||
class Zombie extends Monster{
|
||||
public const NETWORK_ID = self::ZOMBIE;
|
||||
|
@ -33,6 +33,7 @@ use pocketmine\item\ItemFactory;
|
||||
use pocketmine\level\Position;
|
||||
use pocketmine\nbt\tag\ByteTag;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use function get_class;
|
||||
|
||||
class FallingBlock extends Entity{
|
||||
public const NETWORK_ID = self::FALLING_BLOCK;
|
||||
|
@ -31,6 +31,7 @@ use pocketmine\item\Item;
|
||||
use pocketmine\network\mcpe\protocol\AddItemEntityPacket;
|
||||
use pocketmine\network\mcpe\protocol\TakeItemEntityPacket;
|
||||
use pocketmine\Player;
|
||||
use function get_class;
|
||||
|
||||
class ItemEntity extends Entity{
|
||||
public const NETWORK_ID = self::ITEM;
|
||||
|
@ -37,6 +37,7 @@ use pocketmine\nbt\tag\ByteTag;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\network\mcpe\protocol\AddPaintingPacket;
|
||||
use pocketmine\Player;
|
||||
use function ceil;
|
||||
|
||||
class Painting extends Entity{
|
||||
public const NETWORK_ID = self::PAINTING;
|
||||
|
@ -36,6 +36,8 @@ use pocketmine\network\mcpe\protocol\EntityEventPacket;
|
||||
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||
use pocketmine\network\mcpe\protocol\TakeItemEntityPacket;
|
||||
use pocketmine\Player;
|
||||
use function mt_rand;
|
||||
use function sqrt;
|
||||
|
||||
class Arrow extends Projectile{
|
||||
public const NETWORK_ID = self::ARROW;
|
||||
|
@ -27,6 +27,7 @@ use pocketmine\event\entity\ProjectileHitEvent;
|
||||
use pocketmine\network\mcpe\protocol\LevelEventPacket;
|
||||
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||
use pocketmine\utils\Color;
|
||||
use function mt_rand;
|
||||
|
||||
class ExperienceBottle extends Throwable{
|
||||
public const NETWORK_ID = self::XP_BOTTLE;
|
||||
|
@ -41,6 +41,12 @@ use pocketmine\nbt\tag\ByteTag;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\timings\Timings;
|
||||
use function assert;
|
||||
use function atan2;
|
||||
use function ceil;
|
||||
use function sqrt;
|
||||
use const M_PI;
|
||||
use const PHP_INT_MAX;
|
||||
|
||||
abstract class Projectile extends Entity{
|
||||
|
||||
|
@ -34,6 +34,8 @@ use pocketmine\item\Potion;
|
||||
use pocketmine\network\mcpe\protocol\LevelEventPacket;
|
||||
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||
use pocketmine\utils\Color;
|
||||
use function round;
|
||||
use function sqrt;
|
||||
|
||||
class SplashPotion extends Throwable{
|
||||
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\entity\utils;
|
||||
|
||||
use pocketmine\math\Math;
|
||||
use function max;
|
||||
|
||||
abstract class ExperienceUtils{
|
||||
|
||||
|
Reference in New Issue
Block a user