Skip to content

Commit f01758a

Browse files
committed
perf: use orjson for loading the cache files
1 parent ec319bc commit f01758a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Howdy, Bazel user 🤠. Let's get you set up fast with some awesome tooling for
4242

4343
There's a bunch of text here but only because we're trying to spell things out and make them easy. If you have issues, let us know; we'd love your help making things even better and more complete—and we'd love to help you!
4444

45+
This rule optionally uses the `orjson` pip package to significantly speed up JSON processing. You can install it via `pip install orjson -U`.
46+
4547
### First, add this tool to your Bazel setup.
4648

4749
#### If you have a MODULE.bazel file and are using the new [bzlmod](https://bazel.build/external/migration) system

refresh.template.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,11 @@ def _get_headers(compile_action, source_path: str):
543543
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.
544544
try:
545545
with open(cache_file_path) as cache_file:
546-
action_key, cached_headers = json.load(cache_file)
546+
try:
547+
from orjson import loads
548+
action_key, cached_headers = loads(cache_file.read())
549+
except ImportError:
550+
action_key, cached_headers = json.load(cache_file)
547551
except json.JSONDecodeError:
548552
# Corrupted cache, which can happen if, for example, the user kills the program, since writes aren't atomic.
549553
# But if it is the result of a bug, we want to print it before it's overwritten, so it can be reported

0 commit comments

Comments
 (0)