Skip to content

Commit f30a3b0

Browse files
committed
Python: Script: Improve performance by using C++ impl
these changes took performance for loading and writing all files locally 29.60s to 3.17s (that is, using `gather_from_existing`)
1 parent 13c2378 commit f30a3b0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

python/ql/src/meta/ClassHierarchy/process-mrva-results.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def parse_from_file(path: Path) -> set:
7272
if not path.exists():
7373
return set()
7474

75-
text = path.read_text()
76-
assert text.startswith(f"# {VERSION}\n"), f"{path}: {text[:100]}"
75+
f = path.open("r")
76+
assert f.readline().startswith(f"# {VERSION}\n"), path
7777

78-
raw_data = yaml.safe_load(text)
78+
raw_data = yaml.load(f, Loader=yaml.CBaseLoader)
7979
assert len(raw_data["extensions"]) == 1, path
8080
assert raw_data["extensions"][0]["addsTo"]["extensible"] == "typeModel", path
8181

@@ -126,4 +126,6 @@ def gather_from_existing():
126126

127127
data_for_yaml = wrap_in_template(as_lists)
128128

129-
pkg_path.write_text(f"# {VERSION}\n" + yaml.dump(data_for_yaml, indent=2))
129+
f = pkg_path.open("w+")
130+
f.write(f"# {VERSION}\n")
131+
yaml.dump(data_for_yaml, indent=2, stream=f, Dumper=yaml.CDumper)

0 commit comments

Comments
 (0)