php / php/php-src

Use zval storage for php://memory stream

オープン
#11,106 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Category: Streams Feature Status: Needs Triage
主要言語
C
スター
40.4k
フォーク
8.1k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Description

The following code increases the peak memory usage of PHP twice:

$content = str_repeat('hello', 50000);
$h = fopen('php://memory', 'r+');
fwrite($h, $content);

The reason is that PHP cannot currently use copy-on-write when writing to the stream.

This is something that can be worked around by using a custom stream wrapper that keeps data in a zval, as done in e.g.
https://github.com/Nyholm/psr7/pull/230

Using this proved useful for strings longer than ~200K. For smaller strings, using a custom stream wrapper has a higher cost than the memcopy (see https://github.com/Nyholm/psr7/pull/241).

Could it be possible to improve php://memory (and possibly php://temp) to make it use a zval storage to benefit from copy-on-write?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず php://memory ストリームの実装を追跡し、そのストレージ動作を issue で説明されている zval ベースのカスタムラッパーと比較します。php://temp をどのように扱うべきか、また約 200K のサイズ上のトレードオフが設計にどのような影響を与えるかを判断します。ストリームが copy-on-write の恩恵を受けつつ、より小さい文字列のパフォーマンスを低下させないことが完了の条件です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, php
領域
backend, performance
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。