Skip to content

Commit 212b2d4

Browse files
authored
Skip saving page components when skipping compile output (#4653)
Obviously we still have to evaluate the pages to make sure we know about all states, but not saving them to `App.pages` dict reduces high-line memory usage for backend-only process from ~900Mb to ~530Mb on reflex-web.
1 parent 4dc1065 commit 212b2d4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

reflex/app.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,12 @@ def add_page(
558558
meta=meta,
559559
)
560560

561-
def _compile_page(self, route: str):
561+
def _compile_page(self, route: str, save_page: bool = True):
562562
"""Compile a page.
563563
564564
Args:
565565
route: The route of the page to compile.
566+
save_page: If True, the compiled page is saved to self.pages.
566567
"""
567568
component, enable_state = compiler.compile_unevaluated_page(
568569
route, self.unevaluated_pages[route], self.state, self.style, self.theme
@@ -573,7 +574,8 @@ def _compile_page(self, route: str):
573574

574575
# Add the page.
575576
self._check_routes_conflict(route)
576-
self.pages[route] = component
577+
if save_page:
578+
self.pages[route] = component
577579

578580
def get_load_events(self, route: str) -> list[IndividualEventType[[], Any]]:
579581
"""Get the load events for a route.
@@ -873,14 +875,16 @@ def get_compilation_time() -> str:
873875
# If a theme component was provided, wrap the app with it
874876
app_wrappers[(20, "Theme")] = self.theme
875877

878+
should_compile = self._should_compile()
879+
876880
for route in self.unevaluated_pages:
877881
console.debug(f"Evaluating page: {route}")
878-
self._compile_page(route)
882+
self._compile_page(route, save_page=should_compile)
879883

880884
# Add the optional endpoints (_upload)
881885
self._add_optional_endpoints()
882886

883-
if not self._should_compile():
887+
if not should_compile:
884888
return
885889

886890
self._validate_var_dependencies()

0 commit comments

Comments
 (0)