From c80929cc5df098270e8a9e048d187bb1ffeff762 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 1 May 2023 17:25:59 -0700 Subject: [PATCH] perf: use orjson for loading the cache files --- refresh.template.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/refresh.template.py b/refresh.template.py index 273bea7..1945a19 100644 --- a/refresh.template.py +++ b/refresh.template.py @@ -507,7 +507,12 @@ def _get_headers(compile_action, source_path: str): cache_last_modified = os.path.getmtime(cache_file_path) # Do before opening just as a basic hedge against concurrent write, even though we won't handle the concurrent delete case perfectly. try: with open(cache_file_path) as cache_file: - action_key, headers = json.load(cache_file) + try: + from orjson import loads + cache = cache_file.read() + action_key, headers = loads(cache) + except ImportError: + action_key, headers = json.load(cache_file) except json.JSONDecodeError: # Corrupted cache, which can happen if, for example, the user kills the program, since writes aren't atomic. # But if it is the result of a bug, we want to print it before it's overwritten, so it can be reported