serafim/packed-array
Composer 安装命令:
composer require serafim/packed-array
包简介
Typed arrays with reduced memory consumption
README 文档
README
Introduction
PHP packed (typed) arrays are array-like objects that provide a mechanism for reading and writing raw binary data in memory buffers with reduced memory consumption on large amounts of data.
Common PHP arrays grow and shrink dynamically and can have any value. PHP Zend VM perform optimizations so that these arrays are fast. However, in some cases, the standard functionality is not enough and the standard PHP array can take up a very large amount of data, for example, when working with audio, image and video. This is where typed arrays come in. Each entry in a PHP typed array is a raw binary value in one of a number of supported formats, from 8-bit integers to 64-bit floating-point numbers.
For example, an image with a size of 44.968Kb, when loaded into a typed array, takes 45.168Kb of memory. However, if it is unpacked into a native PHP array, then the size of such an image in memory will take 5,633.360Kb. That is more than 120 times!
Below is a graph of the size of the consumed RAM depending on the size of the array (number of elements).
See the bin/memory-usage.php for details on how the this RAM consumption was calculated.
Read/Write
Please note that such arrays are designed to store a large amount of data, however, they are noticeably slower than those builtin PHP arrays during reading and writing.
Reading
| subject | revs | its | mem_peak | mode | rstdev |
|---|---|---|---|---|---|
| benchNative | 10000 | 5 | 1.291mb | 0.018μs | ±1.83% |
| benchSplFixedArray | 10000 | 5 | 1.291mb | 0.028μs | ±3.06% |
| benchPackedInt8 | 10000 | 5 | 1.291mb | 0.087μs | ±1.37% |
| benchPackedUInt8 | 10000 | 5 | 1.291mb | 0.079μs | ±1.65% |
| benchPackedInt16 | 10000 | 5 | 1.291mb | 0.104μs | ±1.12% |
| benchPackedUInt16 | 10000 | 5 | 1.291mb | 0.108μs | ±10.24% |
| benchPackedInt32 | 10000 | 5 | 1.291mb | 0.159μs | ±1.06% |
| benchPackedUInt32 | 10000 | 5 | 1.291mb | 0.174μs | ±0.98% |
| benchPackedInt64 | 10000 | 5 | 1.291mb | 0.160μs | ±0.55% |
| benchPackedFloat32 | 10000 | 5 | 1.291mb | 1.225μs | ±1.46% |
| benchPackedFloat64 | 10000 | 5 | 1.291mb | 1.232μs | ±1.33% |
Writing
| subject | revs | its | mem_peak | mode | rstdev |
|---|---|---|---|---|---|
| benchNative | 10000 | 5 | 1.291mb | 0.019μs | ±2.52% |
| benchSplFixedArray | 10000 | 5 | 1.291mb | 0.032μs | ±2.10% |
| benchPackedInt8 | 10000 | 5 | 1.291mb | 0.088μs | ±2.45% |
| benchPackedUInt8 | 10000 | 5 | 1.291mb | 0.089μs | ±0.50% |
| benchPackedInt16 | 10000 | 5 | 1.291mb | 0.108μs | ±1.42% |
| benchPackedUInt16 | 10000 | 5 | 1.291mb | 0.121μs | ±4.27% |
| benchPackedInt32 | 10000 | 5 | 1.291mb | 0.146μs | ±1.49% |
| benchPackedUInt32 | 10000 | 5 | 1.291mb | 0.153μs | ±1.62% |
| benchPackedInt64 | 10000 | 5 | 1.291mb | 0.220μs | ±1.79% |
| benchPackedFloat32 | 10000 | 5 | 1.291mb | 1.268μs | ±0.91% |
| benchPackedFloat64 | 10000 | 5 | 1.291mb | 1.343μs | ±0.44% |
Installation
This library is available as Composer repository and can be installed using the following command in a root of your project:
$ composer require serafim/packed-array
Quick Start
TODO
serafim/packed-array 适用场景与选型建议
serafim/packed-array 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 10, 最近一次更新时间为 2023 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「library」 「array」 「memory」 「optimized」 「packed」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 serafim/packed-array 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 serafim/packed-array 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 serafim/packed-array 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
repository php library
PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
Trait providing methods to set class properties with an array.
Traits to build collections of specific objects
This adds functions about array. If you feel like there few php built-in functions about array, this will be useful.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-02
