Browse Source

perf: hint the number of threads to TSRM (#655)

* perf: hint the number of threads to TSRM

* fix: PHP 8.2 compat
Kévin Dunglas 1 year ago
parent
commit
b18a079eb9
1 changed files with 9 additions and 4 deletions
  1. 9 4
      frankenphp.c

+ 9 - 4
frankenphp.c

@@ -738,9 +738,16 @@ static void *manager_thread(void *arg) {
     exit(EXIT_FAILURE);
   }
 
+  int num_threads = *((int *)arg);
+  free(arg);
+  arg = NULL;
+
 #ifdef ZTS
-  // TODO: use tsrm_startup() directly as we know the number of expected threads
+#if (PHP_VERSION_ID >= 80300)
+  php_tsrm_startup_ex(num_threads);
+#else
   php_tsrm_startup();
+#endif
   /*tsrm_error_set(TSRM_ERROR_LEVEL_INFO, NULL);*/
 #ifdef PHP_WIN32
   ZEND_TSRMLS_CACHE_UPDATE();
@@ -761,9 +768,7 @@ static void *manager_thread(void *arg) {
 
   frankenphp_sapi_module.startup(&frankenphp_sapi_module);
 
-  threadpool thpool = thpool_init(*((int *)arg));
-  free(arg);
-  arg = NULL;
+  threadpool thpool = thpool_init(num_threads);
 
   uintptr_t rh;
   while ((rh = go_fetch_request())) {