C apis for efficiently adding/checking if a pointer is in a HashTable, reducing hash collisions?
还没有人认领这个 Issue。
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
Description
C pointers in php are aligned to at least ZEND_MM_ALIGNMENT_LOG2 (generally 3 on 64-bit systems, 2 on 32-bit systems), whether they're from malloc or emalloc. (the lowest bit of the pointer represents the address of the byte)
Often, PECLs or php has use cases for inserting, deleting, and iterating over pointers in a hash map, and this is much slower when they collide to the same 1 in 8 (or 1 in 16, for larger value types) hash buckets
-
e.g. in https://github.com/php/php-src/pull/7690 saw a performance improvement from the reduction in hash collisions from shifting the pointers (and issues referencing that PR)
-
For access patterns such as allocating alternating keys and values, or pointers to large objects, there may be even more collisions with emalloc
Adding a struct such as struct zend_ptr_hash { struct zend_hash inner; } and macros/functions for common use cases when pointers are used as keys may help (zend_ptr_hash*). It'd probably be better to use the zend_hash directly.
The helper function static zend_always_inline zend_ulong zend_rotr3(zend_ulong key) in opcache could be used for preserving all bits of the pointer while avoiding hash collisions
The x32 ABI (64 bit pointers and 32 bit zend_long) is not officially supported by PHP, so there's no need for that in this feature request.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先阅读现有的 zend_hash 实现以及 opcache 中的 zend_rotr3 辅助函数,然后查看所引用的 pull request #7690,了解冲突和性能方面的背景。完成的标准是就指针键哈希 API 或等效的直接 zend_hash 方法达成一致并完成实现,在保留指针位的同时减少冲突。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, php
- 领域
- backend
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100