From 1f9a6b010a533d02ffd82ac182e4c9fada129a99 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 7 Jul 2022 11:15:50 +0530 Subject: [PATCH] perf: add `__slots__` to most used classes (#17421) Added slots for these classes: - Session - Created on EACH request - LoginManager - Created on each request - Monitor - Created on each request if monitor is enabled (usually in prod setup) --- frappe/auth.py | 3 +++ frappe/monitor.py | 2 ++ frappe/sessions.py | 2 ++ 3 files changed, 7 insertions(+) diff --git a/frappe/auth.py b/frappe/auth.py index 3737681d71..455e9ee0c5 100644 --- a/frappe/auth.py +++ b/frappe/auth.py @@ -109,6 +109,9 @@ class HTTPRequest: class LoginManager: + + __slots__ = ("user", "info", "full_name", "user_type", "resume") + def __init__(self): self.user = None self.info = None diff --git a/frappe/monitor.py b/frappe/monitor.py index e151944b1f..8d5391cb77 100644 --- a/frappe/monitor.py +++ b/frappe/monitor.py @@ -30,6 +30,8 @@ def log_file(): class Monitor: + __slots__ = ("data",) + def __init__(self, transaction_type, method, kwargs): try: self.data = frappe._dict( diff --git a/frappe/sessions.py b/frappe/sessions.py index 67b58e1d89..f7c4b34470 100644 --- a/frappe/sessions.py +++ b/frappe/sessions.py @@ -213,6 +213,8 @@ def generate_csrf_token(): class Session: + __slots__ = ("user", "device", "user_type", "full_name", "data", "time_diff", "sid") + def __init__(self, user, resume=False, full_name=None, user_type=None): self.sid = cstr( frappe.form_dict.get("sid") or unquote(frappe.request.cookies.get("sid", "Guest"))