rust-threads: force Rayon to respect the worker count in config
authorRaphaël Gomès <rgomes@octobus.net>
Sun, 10 Nov 2019 07:30:14 -0800
changeset 43505 47fac1692ede
parent 43504 a78a65c33b5a
child 43506 9f70512ae2cf
rust-threads: force Rayon to respect the worker count in config As per the inline comment, this is a workaround because Rust code does not yet know how to read config files. Differential Revision: https://phab.mercurial-scm.org/D7310
mercurial/dirstate.py
--- a/mercurial/dirstate.py	Fri Oct 18 07:20:26 2019 +0100
+++ b/mercurial/dirstate.py	Sun Nov 10 07:30:14 2019 -0800
@@ -1109,6 +1109,17 @@
             use_rust = False
 
         if use_rust:
+            # Force Rayon (Rust parallelism library) to respect the number of
+            # workers. This is a temporary workaround until Rust code knows
+            # how to read the config file.
+            numcpus = self._ui.configint("worker", "numcpus")
+            if numcpus is not None:
+                encoding.environ.setdefault(b'RAYON_NUM_THREADS', b'%d' % numcpus)
+
+            workers_enabled = self._ui.configbool("worker", "enabled", True)
+            if not workers_enabled:
+                encoding.environ[b"RAYON_NUM_THREADS"] = b"1"
+
             (
                 lookup,
                 modified,