1 of 16

かんぱーい

tested on php 7.4

2 of 16

インターン化

同じ文字列を共通領域に保管してメモリ使用量を節約する

3 of 16

参照カウンタを使ってる

4 of 16

name: (interned, is_ref=0)='@ariaki4dev'

hello: (refcount=1, is_ref=0)='Hello, @ariaki4dev'

5 of 16

hoge: (refcount=2, is_ref=0)=array (0 => (refcount=1, is_ref=0)='php')

fuga: (refcount=1, is_ref=0)=array (0 => (interned, is_ref=0)='php')

6 of 16

hoge: (interned, is_ref=0)='@ariaki4dev'

fuga: (refcount=0, is_ref=0)=1234

piyo: (refcount=2, is_ref=0)=array

(0 => (refcount=1, is_ref=0)='php',

1 => (refcount=1, is_ref=0)='conference',

2 => (refcount=0, is_ref=0)=2020)

7 of 16

→ 0

→ 80

8 of 16

name: (interned, is_ref=0)='@ariaki4dev'

name: (refcount=2, is_ref=1)='@ariaki4dev'

nick: (refcount=2, is_ref=1)='@ariaki4dev'

nick: (refcount=1, is_ref=1)='@ariaki4dev'

9 of 16

$name

$nick

10 of 16

コピーオンライト

オブジェクトがコピーされた時点ではメモリを確保せず、

変更が必要な時点になってはじめてメモリを確保する。

11 of 16

→ 0

→ 32

→ 408

→ 32

12 of 16

GCの挙動

13 of 16

→ 864

→ 864

→ 32

→ 80

14 of 16

→ 1280

→ 352

→ 352

→ 80

PHP 7.4〜

15 of 16

GCの挙動

  • 循環参照もGCによって回収される(PHP5.3〜)
  • GCタイミングは固定→オブジェクト10,000件に到達

16 of 16

↓更に詳しくはこちら↓

https://speakerdeck.com/ariaki/ooc-2020