From 05e5e1c90b2c7fee821efaf9214c5ae36a0aa4a3 Mon Sep 17 00:00:00 2001 From: Max Marrone Date: Mon, 23 Dec 2024 15:09:46 -0500 Subject: [PATCH] Avoid creating a process pool if we know we don't have any work for it. --- .../robot_server/persistence/_migrations/up_to_3.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/robot-server/robot_server/persistence/_migrations/up_to_3.py b/robot-server/robot_server/persistence/_migrations/up_to_3.py index b4382545dbf..9fc901d2c0c 100644 --- a/robot-server/robot_server/persistence/_migrations/up_to_3.py +++ b/robot-server/robot_server/persistence/_migrations/up_to_3.py @@ -191,6 +191,12 @@ def _migrate_db_commands( the work across subprocesses. Each subprocess extracts, migrates, and inserts all of the commands for a single run. """ + # Performance optimization: If we have nothing to migrate, don't even create the + # process pool. This avoids the heavy imports in the preload. + # On my laptop, this shaves ~1.5s off of each of our integration tests. + if not run_ids: + return + mp = multiprocessing.get_context("forkserver") mp.set_forkserver_preload(_up_to_3_worker.imports)