All Projects → pmmp → ext-encoding

pmmp / ext-encoding

Licence: other
High-performance specialized replacements for PHP's pack() and unpack() functions

Programming Languages

PHP
23972 projects - #3 most used programming language
C++
36643 projects - #6 most used programming language
M4
1887 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to ext-encoding

mdserver-web
Simple Linux Panel
Stars: ✭ 1,064 (+8084.62%)
Mutual labels:  php80, php81
RakLib
RakNet server implementation written in PHP
Stars: ✭ 58 (+346.15%)
Mutual labels:  php81
Math
PHP library containing math related code used in PocketMine-MP
Stars: ✭ 35 (+169.23%)
Mutual labels:  php81
laravel-username-generator
Automatically generate usernames for Laravel User Model
Stars: ✭ 37 (+184.62%)
Mutual labels:  php80
BedrockProtocol
An implementation of the Minecraft: Bedrock Edition protocol in PHP
Stars: ✭ 59 (+353.85%)
Mutual labels:  php81
ext-chunkutils2
PHP extension in C++ implementing the modern Minecraft: Bedrock subchunk format for PocketMine-MP 4.0
Stars: ✭ 26 (+100%)
Mutual labels:  php81
magento2-fast-vm
Optimal vagrant developer box for Magento2. Folders synced by nfs/rsync. This box includes Magento developer utilities.
Stars: ✭ 89 (+584.62%)
Mutual labels:  php81
framework
FEAST Framework
Stars: ✭ 66 (+407.69%)
Mutual labels:  php81

ext-encoding

High-performance specialized replacements for PHP's pack() and unpack() functions

VarInts

VarInts are heavily used by the Bedrock protocol, the theory being to reduce the size of integer types on the wire. This format is borrowed from protobuf.

Implemented in PHP, it's abysmally slow, due to repeated calls to chr() and ord() in a loop, as well as needing workarounds for PHP's lack of logical rightshift.

Implemented in this extension, we see performance gains of around 10x compared to Binary::writeVarInt() and around 8x compared to Binary::writeUnsignedVarInt(). This is extremely significant due to the number of hot paths affected by such a performance gain (e.g. chunk encoding will benefit significantly).

Fixed size types

Under a profiler, it becomes obvious that PHP's pack() and unpack() functions are horribly slow due to the format code parsing. This is a problem for PocketMine-MP because these functions are used in hot paths to encode packets (pmmp/BinaryUtils).

This extension implements specialized replacements for these functions, such as:

  • readShortLE()
  • readShortBE()
  • readIntLE()
  • readIntBE()

and various others.

In synthetic benchmarks, it's shown that these functions are around 3x faster than unpack(). When taking into account the overhead of Binary class and the possibility of implementing a native Binary class directly, the performance difference is closer to 7x faster.

TODO

  • Implement Binary as an extension class.
  • Implement BinaryStream as an extension class (will elide 2 PHP function calls in most cases, saving a bunch of time).
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].