{"id":15142686,"url":"https://github.com/pmmp/ext-encoding","last_synced_at":"2025-08-05T09:21:51.830Z","repository":{"id":51164402,"uuid":"418679982","full_name":"pmmp/ext-encoding","owner":"pmmp","description":"High-performance `ByteBuffer` implementation for PHP, planned for use in a future version of PocketMine-MP","archived":false,"fork":false,"pushed_at":"2025-06-21T20:59:22.000Z","size":192,"stargazers_count":21,"open_issues_count":6,"forks_count":3,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-06-21T21:30:01.746Z","etag":null,"topics":["php-extension","php80","php81","php82"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pmmp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-10-18T21:52:40.000Z","updated_at":"2025-06-21T20:59:26.000Z","dependencies_parsed_at":"2022-09-22T16:03:52.993Z","dependency_job_id":"fac79141-ca1d-4011-8d56-0c27a3786b64","html_url":"https://github.com/pmmp/ext-encoding","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/pmmp/ext-encoding","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmmp%2Fext-encoding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmmp%2Fext-encoding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmmp%2Fext-encoding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmmp%2Fext-encoding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmmp","download_url":"https://codeload.github.com/pmmp/ext-encoding/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmmp%2Fext-encoding/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268867866,"owners_count":24320454,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-05T02:00:12.334Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php-extension","php80","php81","php82"],"created_at":"2024-09-26T09:43:39.202Z","updated_at":"2025-08-05T09:21:51.775Z","avatar_url":"https://github.com/pmmp.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ext-encoding\nThis extension implements a `ByteBuffer` class, a high-performance alternative for [`pocketmine/binaryutils`](https://github.com/pmmp/BinaryUtils).\n\n## :warning: This extension is EXPERIMENTAL\n\nThere is a high likelihood that the extension's classes may crash or behave incorrectly.\nDo not use this extension for anything you don't want to get horribly corrupted.\n\n## API\nA recent IDE stub can usually be found in our [custom stubs repository](https://github.com/pmmp/phpstorm-stubs/blob/fork/encoding/encoding.php).\n\n#### :warning: The API design is not yet finalized. Everything is still subject to change prior to the 1.0.0 release.\n\n## Real-world performance tests\n- [`pocketmine/nbt`](https://github.com/pmmp/NBT) was tested with release 0.2.1, and showed 1.5x read and 2x write performance with some basic synthetic tests.\n\n## Performance considerations\n### VarInts\nVarInts are heavily used by the Bedrock protocol, the theory being to reduce the size of integer types on the wire.\nThis format is borrowed from [protobuf](https://developers.google.com/protocol-buffers/docs/encoding).\n\nImplemented 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.\n\nCompared to `BinaryStream`, `ByteBuffer` offers a performance improvement of 5-10x (depending on the size of the value and other conditions, YMMV) with both signed and unsigned varints.\n\nThis is extremely significant for PocketMine-MP due to the number of hot paths affected by such a performance gain (e.g. chunk encoding will benefit significantly).\n\n### Fixed size types\nUnder a profiler, it becomes obvious that PHP's `pack()` and `unpack()` functions are abysmally slow, due to the cost of parsing the formatting code argument.\nThis parsing takes over 90% of the time spent in `pack()` and `unpack()`.\nThis overhead can be easily avoided when the types of data used are known in advance.\n\nThis extension implements specialized functions for writing big and little endian byte/short/int/long/float/double. \nDepending on the type and other factors, these functions typically show a 3-4x performance improvement compared to `BinaryStream`.\n\n### Linear memory allocations\n`BinaryStream` and similar PHP-land byte-buffer implementations often use strings and use the `.=` concatenation operator.\nThis is problematic, because the entire string will be reallocated every time something is appended to it.\nWhile this isn't a big issue for small buffers, the performance of writing to large buffers progressively degrades.\n\n`ByteBuffer` uses exponential scaling (factor of 2) to minimize buffer reallocations at the cost of potentially wasting some memory.\nThis means that the internal buffer size is doubled when the buffer runs out of space.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmmp%2Fext-encoding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmmp%2Fext-encoding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmmp%2Fext-encoding/lists"}