Performance penalty for builtin/extension functions due to interrupt checks
还没有人认领这个 Issue。
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.1k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
I was profiling an extension that's intended to act as a faster replacement for the pack() and unpack() functions. The functions in the extension are very fast - just a few instructions each.
During profiling I discovered, much to my surprise, that the overhead of the DO_FCALL opcode far exceeded the time actually spent in my function, and that 2/3rds of the overhead was coming from ZEND_VM_FCALL_INTERRUPT_CHECK.
Doing some digging I found that this interrupt check runs after every single internal function call. This means that my extension's functions are being overshadowed by interrupt checks on every call which are >5x slower than the actual function itself.
The net result overall is less visible (a 5-10% performance degradation in my synthetic test script), but I have to ask if there's a better way to do this. Why is PHP checking for interrupts after every internal function call? I get it for stuff like network and I/O functions which could take a long time, but not every builtin function is like that. For the fast ones, this is an unavoidable and (probably) unnecessary performance penalty.
I don't know much about how the interrupt system works, but my feeling is that there has to be a better way to implement it than having every internal function call pay such a penalty. Even if there was a way to avoid this interrupt check with some ZEND_ACC flag that would tell the engine a function is "fast" and not to do the interrupt check?
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
该 issue 提到的是 DO_FCALL 和 ZEND_VM_FCALL_INTERRUPT_CHECK,而不是某个文件。首先追踪 VM 在哪里对内部调用执行中断检查,以及快速扩展函数是如何表示的。完成标准应包括一个经过审查的引擎级方案,以及表明在不削弱中断行为的情况下开销有所降低的基准测试证据。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, php
- 领域
- compilers, performance
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 28/100