Commit 66cce22
committed
deepclone_from_array: hydrate closure-bearing nodes as native lazy ghosts
On PHP 8.4+, object nodes whose payload slots or replayed __unserialize
state carry a named-closure or const-expr-closure marker are created as
uninitialized lazy ghosts: every object identity exists when the call
returns (back-references, shared &-references and === behave as for eager
nodes), but per-node hydration, closure resolution included, runs on first
engine access. Closure-bearing __wakeup/__unserialize nodes replay their
hook at the end of their own initialization; per-entry validation stays
inside the call. Nodes without closure markers hydrate eagerly as before
(copy-on-write makes plain value slots cheaper to hydrate than to ghost),
as does everything on PHP 8.2/8.3.
Shared state lives in the internal-only DeepClone\HydrationContext;
ReflectionClass::getLazyInitializer() returns a Closure bound to it,
shared by all ghosts of one call. Structural validation and
allowed_classes enforcement (including the const-expr gate) stay eager;
only value-level resolution errors surface at first access, where the
engine reverts the ghost and keeps it retryable.
Measured against v0.7.2 (20k-node graphs, release 8.4): closure-rich
graphs hydrate 4-6x faster on creation and partial consumption, occupy
2-3x less memory while untouched, and tear down about 2x faster when
dropped untouched; fully traversed graphs pay a comparable total; scalar
graphs are unchanged.
Also fixes two pre-existing issues lazy hydration would have amplified:
shared &-references bound to typed declared properties now register the
property as a type source instead of tripping the engine's deref
assertion, and object-ref markers resolved against ref slots are
order-independent by-value snapshots.1 parent 0b0c2ad commit 66cce22
12 files changed
Lines changed: 1949 additions & 20 deletions
File tree
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
8 | 59 | | |
9 | 60 | | |
10 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
90 | 157 | | |
91 | 158 | | |
92 | 159 | | |
| |||
0 commit comments