Skip to content

Commit

Permalink
perf: preload more modules (frappe#21557)
Browse files Browse the repository at this point in the history
* perf: preload more modules

- bleach is used frequently for sanitization
- File gets imported anytime a private file is viewed. Indirect import
  of PIL is costly in each worker.

* test: warm up perf test
  • Loading branch information
ankush committed Jul 2, 2023
1 parent f5b93cc commit d799036
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions frappe/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@

# If gc.freeze is done then importing modules before forking allows us to share the memory
if frappe._tune_gc:
import bleach
import pydantic

import frappe.boot
import frappe.client
import frappe.core.doctype.file.file
import frappe.core.doctype.user.user
import frappe.database.mariadb.database # Load database related utils
import frappe.database.query
import frappe.desk.desktop # workspace
import frappe.desk.form.save
import frappe.model.db_query
import frappe.query_builder
import frappe.utils.background_jobs # Enqueue is very common
Expand Down
3 changes: 3 additions & 0 deletions frappe/tests/test_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def test_controller_caching(self):
def test_get_value_limits(self):
# check both dict and list style filters
filters = [{"enabled": 1}, [["enabled", "=", 1]]]

# Warm up code
frappe.db.get_values("User", filters=filters[0], limit=1)
for filter in filters:
with self.assertRowsRead(1):
self.assertEqual(1, len(frappe.db.get_values("User", filters=filter, limit=1)))
Expand Down

0 comments on commit d799036

Please sign in to comment.