Skip to content

Commit

Permalink
Change: speed-up startup by using C-powered YAML loader (#403)
Browse files Browse the repository at this point in the history
The C-powered loader is about 6 times faster, and makes the startup
go from ~30s to ~5s.
  • Loading branch information
TrueBrain authored Jul 19, 2023
1 parent d70805f commit fe7796f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions bananas_api/index/common_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, folder):

def read_content_version(self, path, version, load_as_object=False):
with open(f"{self.folder}/{path}/versions/{version}.yaml") as f:
version_data = yaml.safe_load(f.read())
version_data = yaml.load(f.read(), Loader=yaml.CSafeLoader)

# YAML converts this in a datetime() for us, and marshmallow
# expects a string. So output it as an ISO-8601 again.
Expand All @@ -99,14 +99,14 @@ def _read_content_entry(self, content_type, category, unique_id):
path = f"{category}/{unique_id}"

with open(f"{self.folder}/{path}/global.yaml") as f:
package_data = yaml.safe_load(f.read())
package_data = yaml.load(f.read(), Loader=yaml.CSafeLoader)

if package_data.get("blacklisted"):
return None

package_data["authors"] = []
with open(f"{self.folder}/{path}/authors.yaml") as f:
authors_data = yaml.safe_load(f.read())
authors_data = yaml.load(f.read(), Loader=yaml.CSafeLoader)

for author_data in authors_data.get("authors", []):
package_data["authors"].append(author_data)
Expand Down
2 changes: 1 addition & 1 deletion bananas_api/tool_reclassify/reclassify.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def reclassify_and_update_metadata(index_folder, storage_folder, category, uniqu

# Load the global data to find things like the name.
with open(f"{index_folder}/{category}/{unique_id}/global.yaml") as f:
global_data = yaml.safe_load(f.read())
global_data = yaml.load(f.read(), Loader=yaml.CSafeLoader)

name = data.get("name", global_data.get("name", "Unknown"))

Expand Down
2 changes: 1 addition & 1 deletion bananas_api/web_routes/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def click_client_file(client_file):
return

with open(client_file, "r") as fp:
data = yaml.safe_load(fp.read())
data = yaml.load(fp.read(), Loader=yaml.CSafeLoader)

for client in data["clients"]:
_clients[client["id"]] = client["redirect-uri"]
Expand Down
2 changes: 1 addition & 1 deletion regression_runner/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ async def _handle_files(filenames):

try:
with open(filename, "r") as f:
data = yaml.safe_load(f)
data = yaml.load(f, Loader=yaml.CSafeLoader)

await _handle_file(data)
log.success("Regression test passed")
Expand Down

0 comments on commit fe7796f

Please sign in to comment.