From bd7e1edff511c8410acfb640d005502d66910b41 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 5 Jul 2014 12:02:01 -0400 Subject: Make memoized zip manifests opt-in using the PKG_RESOURCES_CACHE_ZIP_MANIFESTS environment variable. Ref #154. --- CHANGES.txt | 8 ++++++-- pkg_resources.py | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 003e2d5d..ef456a7e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,8 +6,12 @@ CHANGES 5.4 --- -* Issue #154: Cache the reading of the zip file index for cases where the - same zip-file is used for multiple packages (like PEX). +* Issue #154: ``pkg_resources`` will now cache the zip manifests rather than + re-processing the same file from disk multiple times, but only if the + environment variable ``PKG_RESOURCES_CACHE_ZIP_MANIFESTS`` is set. Clients + that package many modules in the same zip file will see some improvement + in startup time by enabling this feature. This feature is not enabled by + default because it causes a substantial increase in memory usage. --- 5.3 diff --git a/pkg_resources.py b/pkg_resources.py index f4c7f5e9..3782384a 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -1602,7 +1602,11 @@ class ZipProvider(EggProvider): """Resource support for zips and eggs""" eagers = None - _zip_manifests = ZipManifests() + _zip_manifests = ( + MemoizedZipManifests() + if os.environ.get('PKG_RESOURCES_CACHE_ZIP_MANIFESTS') else + ZipManifests() + ) def __init__(self, module): EggProvider.__init__(self, module) -- cgit v1.2.3