From e621a0ce3d0067747d1d7afb286127f14b8d27b1 Mon Sep 17 00:00:00 2001 From: Ross Patterson Date: Mon, 16 Jan 2012 22:46:38 +0000 Subject: [PATCH] Avoid sorting the working set and requirements when it won't be logged. Backport 124059 from trunk. --- CHANGES.txt | 7 +++++++ src/zc/buildout/easy_install.py | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 92c8d8472..f3019ff4b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,13 @@ Change History 1.4.5 (unreleased) ================== +- Avoid sorting the working set and requirements when it won't be + logged. When profiling a simple buildout with 10 parts with + identical and large working sets, this resulted in a decrease of run + time from 93.411 to 15.068 seconds, about a 6 fold improvement. To + see the benefit be sure to run without any increase in verbosity + ("-v" option). (rossp) + - Introduce a cache for the expensive `buildout._dir_hash` function. - Remove duplicate path from script's sys.path setup. diff --git a/src/zc/buildout/easy_install.py b/src/zc/buildout/easy_install.py index 282e71bd9..6177eb973 100644 --- a/src/zc/buildout/easy_install.py +++ b/src/zc/buildout/easy_install.py @@ -1200,6 +1200,15 @@ def __str__(self): return "Couldn't find a distribution for %r." % str(req) def _log_requirement(ws, req): + if not logger.isEnabledFor(logging.DEBUG): + # Sorting the working set and iterating over it's requirements + # is expensive, so short cirtuit the work if it won't even be + # logged. When profiling a simple buildout with 10 parts with + # identical and large working sets, this resulted in a + # decrease of run time from 93.411 to 15.068 seconds, about a + # 6 fold improvement. + return + ws = list(ws) ws.sort() for dist in ws: