Skip to content

Commit 7f74a30

Browse files
authored
Reduce observer overhead when restoring script from opcache (#9413)
* Reduce observer overhead when restoring script from opcache * typo * Split loops to keep notifications in case of redeclaration errors
1 parent b485a3e commit 7f74a30

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

ext/opcache/zend_accelerator_util_funcs.c

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,12 @@ void zend_accel_move_user_classes(HashTable *src, uint32_t count, zend_script *s
140140
src->pDestructor = orig_dtor;
141141
}
142142

143-
static void zend_accel_function_hash_copy(HashTable *target, HashTable *source)
143+
static zend_always_inline void _zend_accel_function_hash_copy(HashTable *target, HashTable *source, bool call_observers)
144144
{
145145
zend_function *function1, *function2;
146146
Bucket *p, *end;
147147
zval *t;
148148

149-
bool call_observers = zend_observer_function_declared_observed;
150-
151149
zend_hash_extend(target, target->nNumUsed + source->nNumUsed, 0);
152150
p = source->arData;
153151
end = p + source->nNumUsed;
@@ -164,6 +162,7 @@ static void zend_accel_function_hash_copy(HashTable *target, HashTable *source)
164162
}
165163
}
166164
target->nInternalPointer = 0;
165+
167166
return;
168167

169168
failure:
@@ -183,13 +182,21 @@ static void zend_accel_function_hash_copy(HashTable *target, HashTable *source)
183182
}
184183
}
185184

186-
static void zend_accel_class_hash_copy(HashTable *target, HashTable *source)
185+
static zend_always_inline void zend_accel_function_hash_copy(HashTable *target, HashTable *source)
186+
{
187+
_zend_accel_function_hash_copy(target, source, 0);
188+
}
189+
190+
static zend_never_inline void zend_accel_function_hash_copy_notify(HashTable *target, HashTable *source)
191+
{
192+
_zend_accel_function_hash_copy(target, source, 1);
193+
}
194+
195+
static zend_always_inline void _zend_accel_class_hash_copy(HashTable *target, HashTable *source, bool call_observers)
187196
{
188197
Bucket *p, *end;
189198
zval *t;
190199

191-
bool call_observers = zend_observer_class_linked_observed;
192-
193200
zend_hash_extend(target, target->nNumUsed + source->nNumUsed, 0);
194201
p = source->arData;
195202
end = p + source->nNumUsed;
@@ -238,6 +245,16 @@ static void zend_accel_class_hash_copy(HashTable *target, HashTable *source)
238245
target->nInternalPointer = 0;
239246
}
240247

248+
static zend_always_inline void zend_accel_class_hash_copy(HashTable *target, HashTable *source)
249+
{
250+
_zend_accel_class_hash_copy(target, source, 0);
251+
}
252+
253+
static zend_never_inline void zend_accel_class_hash_copy_notify(HashTable *target, HashTable *source)
254+
{
255+
_zend_accel_class_hash_copy(target, source, 1);
256+
}
257+
241258
void zend_accel_build_delayed_early_binding_list(zend_persistent_script *persistent_script)
242259
{
243260
zend_op_array *op_array = &persistent_script->script.main_op_array;
@@ -377,11 +394,19 @@ zend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script,
377394
}
378395

379396
if (zend_hash_num_elements(&persistent_script->script.function_table) > 0) {
380-
zend_accel_function_hash_copy(CG(function_table), &persistent_script->script.function_table);
397+
if (EXPECTED(!zend_observer_function_declared_observed)) {
398+
zend_accel_function_hash_copy(CG(function_table), &persistent_script->script.function_table);
399+
} else {
400+
zend_accel_function_hash_copy_notify(CG(function_table), &persistent_script->script.function_table);
401+
}
381402
}
382403

383404
if (zend_hash_num_elements(&persistent_script->script.class_table) > 0) {
384-
zend_accel_class_hash_copy(CG(class_table), &persistent_script->script.class_table);
405+
if (EXPECTED(!zend_observer_class_linked_observed)) {
406+
zend_accel_class_hash_copy(CG(class_table), &persistent_script->script.class_table);
407+
} else {
408+
zend_accel_class_hash_copy_notify(CG(class_table), &persistent_script->script.class_table);
409+
}
385410
}
386411

387412
if (persistent_script->num_early_bindings) {

0 commit comments

Comments
 (0)