Skip to content

Commit 42eab31

Browse files
committed
perf: use orjson for caching files
1 parent 037389e commit 42eab31

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

refresh.template.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -547,15 +547,24 @@ def _get_headers(compile_action, source_path: str):
547547
# Cache for future use
548548
if output_file:
549549
os.makedirs(os.path.dirname(cache_file_path), exist_ok=True)
550-
with open(cache_file_path, 'w') as cache_file:
551-
json.dump((compile_action.actionKey, list(headers)), cache_file)
550+
_cache_compile_action(compile_action, cache_file_path, headers)
552551

553552
if {exclude_headers} == "external":
554553
headers = {header for header in headers if _file_is_in_main_workspace_and_not_external(header)}
555554

556555
return headers
556+
557557
_get_headers.has_logged = False
558558

559+
def _cache_compile_action(compile_action, cache_file_path, headers):
560+
cache = (compile_action.actionKey, list(headers))
561+
try:
562+
from orjson import dumps
563+
with open(cache_file_path, 'wb') as cache_file:
564+
cache_file.write(dumps(cache))
565+
except ImportError:
566+
with open(cache_file_path, 'w') as cache_file:
567+
json.dump(cache, cache_file)
559568

560569
def _get_files(compile_action):
561570
"""Gets the ({source files}, {header files}) clangd should be told the command applies to."""

0 commit comments

Comments
 (0)