From de45853c99bda753e7b85d70e2612ea30a9d0bfd Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 8 Aug 2018 13:33:49 -0700 Subject: [PATCH] OpenAPI: Import yamole inside a function for performance. This saves about 1% of the runtime of `manage.py showmigrations` --- zerver/lib/openapi.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/zerver/lib/openapi.py b/zerver/lib/openapi.py index 1a44d3fbca..506bf74e10 100644 --- a/zerver/lib/openapi.py +++ b/zerver/lib/openapi.py @@ -3,8 +3,6 @@ import os from typing import Any, Dict, List, Optional -from yamole import YamoleParser - OPENAPI_SPEC_PATH = os.path.abspath(os.path.join( os.path.dirname(__file__), '../openapi/zulip.yaml')) @@ -26,6 +24,11 @@ class OpenAPISpec(): self.last_update = None # type: Optional[float] def reload(self) -> None: + # Because importing yamole (and in turn, yaml) takes + # significant time, and we only use python-yaml for our API + # docs, importing it lazily here is a significant optimization + # to `manage.py` startup. + from yamole import YamoleParser self.last_update = os.path.getmtime(self.path) with open(self.path) as f: yaml_parser = YamoleParser(f)