Skip to content

Commit 2895273

Browse files
authored
perf: extend table on env startup instead of letting zend_hash_copy do it (#2272)
this can potentially save us a few internal calls to zend_hash_do_resize while it loops over the source table (main_thread_env) `8 -> 16 -> 32 -> 64 -> 128` becomes `8 -> target_size (rounded to power of 2) 128`.
1 parent f595cea commit 2895273

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

frankenphp.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ bool frankenphp_shutdown_dummy_request(void) {
288288
}
289289

290290
void get_full_env(zval *track_vars_array) {
291+
zend_hash_extend(Z_ARR_P(track_vars_array),
292+
zend_hash_num_elements(main_thread_env), 0);
291293
zend_hash_copy(Z_ARR_P(track_vars_array), main_thread_env, NULL);
292294
}
293295

@@ -813,6 +815,7 @@ void frankenphp_register_server_vars(zval *track_vars_array,
813815
frankenphp_server_vars vars) {
814816
HashTable *ht = Z_ARRVAL_P(track_vars_array);
815817
zend_hash_extend(ht, vars.total_num_vars, 0);
818+
zend_hash_copy(ht, main_thread_env, NULL);
816819

817820
// update values with variable strings
818821
#define FRANKENPHP_REGISTER_VAR(name) \
@@ -958,9 +961,7 @@ static void frankenphp_register_variables(zval *track_vars_array) {
958961
* $_SERVER and $_ENV should only contain values from the original
959962
* environment, not values added though putenv
960963
*/
961-
zend_hash_copy(Z_ARR_P(track_vars_array), main_thread_env, NULL);
962-
963-
/* import CGI variables from the request context in go */
964+
/* import environment and CGI variables from the request context in go */
964965
go_register_server_variables(thread_index, track_vars_array);
965966

966967
/* Some variables are already present in SG(request_info) */

0 commit comments

Comments
 (0)