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

perf: use orjson for writing compile_commands #118

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
perf: use orjson for loading the cache files
  • Loading branch information
aminya committed Jan 3, 2024
commit f01758a0d9c940831c603c6fd9d1152f6b382d96
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Howdy, Bazel user 🤠. Let's get you set up fast with some awesome tooling for

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!

This rule optionally uses the `orjson` pip package to significantly speed up JSON processing. You can install it via `pip install orjson -U`.

### First, add this tool to your Bazel setup.

#### If you have a MODULE.bazel file and are using the new [bzlmod](https://bazel.build/external/migration) system
Expand Down
6 changes: 5 additions & 1 deletion refresh.template.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,11 @@ 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, cached_headers = json.load(cache_file)
try:
from orjson import loads
action_key, cached_headers = loads(cache_file.read())
except ImportError:
action_key, cached_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