comparison setup.py @ 43044:f9d35f01b8b3

setup: build extensions in parallel by default The build_ext distutils command in Python 3.5+ has a "parallel" option that controls whether to build extensions in parallel. It is disabled by default (None) and can be set to an integer value for number of cores or True to indicate use all available CPU cores. This commit changes our build_ext command override to set "parallel" to True unless a value has been provided by the caller. On my machine, this makes `python setup.py build_ext` 1-4s faster. It is worth noting that at this time, each individual source file constituting the extension is still built serially. For Mercurial, this means that we can't build faster than the slowest-to-build extension, which is the zstd extension by a long shot. This means that setup.py is still not very efficient at utilizing multiple cores. But we're better than before. Differential Revision: https://phab.mercurial-scm.org/D6923 # no-check-commit because of foo_bar naming
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 30 Sep 2019 17:26:41 -0700
parents 268662aac075
children 2372284d9457
comparison
equal deleted inserted replaced
43043:e370f9e4bfad 43044:f9d35f01b8b3
487 def initialize_options(self): 487 def initialize_options(self):
488 self.zstd = True 488 self.zstd = True
489 self.rust = True 489 self.rust = True
490 490
491 return build_ext.initialize_options(self) 491 return build_ext.initialize_options(self)
492
493 def finalize_options(self):
494 # Unless overridden by the end user, build extensions in parallel.
495 # Only influences behavior on Python 3.5+.
496 if getattr(self, 'parallel', None) is None:
497 self.parallel = True
498
499 return build_ext.finalize_options(self)
492 500
493 def build_extensions(self): 501 def build_extensions(self):
494 ruststandalones = [e for e in self.extensions 502 ruststandalones = [e for e in self.extensions
495 if isinstance(e, RustStandaloneExtension)] 503 if isinstance(e, RustStandaloneExtension)]
496 self.extensions = [e for e in self.extensions 504 self.extensions = [e for e in self.extensions