From b2d8c1b6cc84efea873bd91896e786f4d3f0c565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Tue, 9 Apr 2019 18:28:19 -0700 Subject: [PATCH] Improve cold start time by moving kubernetes import "import kubernetes" takes a long time. Moving this import improves "tutor --version" from 0.8s to 0.3s. --- CHANGELOG.md | 1 + tutor/k8s.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21548b9..ca02af8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Latest +- [Improvement] Improve CLI cold start performance - [Improvement] Allow uppercase "Y" and "N" as answers to boolean questions ## v3.3.4 (2019-04-09) diff --git a/tutor/k8s.py b/tutor/k8s.py index 10a2ac9..21ffa87 100644 --- a/tutor/k8s.py +++ b/tutor/k8s.py @@ -1,5 +1,4 @@ import click -import kubernetes from . import config as tutor_config from . import env as tutor_env @@ -138,6 +137,8 @@ class K8s: @property def client(self): if self.CLIENT is None: + # Import moved here for performance reasons + import kubernetes kubernetes.config.load_kube_config() self.CLIENT = kubernetes.client.CoreV1Api() return self.CLIENT