Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build perf: avoid thousands of needless file opens and yaml parses #11190

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ssg/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,27 @@

import ssg.yaml

try:
from functools import lru_cache
except ImportError: # Viva la python 2.7
from functools import wraps

def lru_cache(maxsize):

def support_maxsize_on_suse15_wrapper(user_function):
cache = {}

@wraps(user_function)
def wrapper(*args):
key = tuple(args)
if key not in cache:
cache[key] = user_function(*args)
return cache[key]
return wrapper
return support_maxsize_on_suse15_wrapper


@lru_cache(maxsize=16)
def load(components_dir):
components = {}
for component_filename in os.listdir(components_dir):
Expand Down
Loading