Skip to content

Commit

Permalink
perf: use orjson for loading the cache files
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed May 2, 2023
1 parent 42eab31 commit c80929c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion refresh.template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c80929c

Please sign in to comment.