Skip to content

Commit 4bb036a

Browse files
committed
add progrss for imports and statefulizing
1 parent 6fbd8b1 commit 4bb036a

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

reflex/app.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,8 +1186,8 @@ def get_compilation_time() -> str:
11861186
progress.start()
11871187
task = progress.add_task(
11881188
f"[{get_compilation_time()}] Compiling:",
1189-
total=len(self._pages)
1190-
+ (len(self._unevaluated_pages) * 2)
1189+
total=len(self._unevaluated_pages)
1190+
+ ((len(self._unevaluated_pages) + len(self._pages)) * 3)
11911191
+ fixed_pages_within_executor
11921192
+ adhoc_steps_without_executor
11931193
+ plugin_count,
@@ -1272,22 +1272,28 @@ def memoized_toast_provider():
12721272
all_imports.update(custom_components_imports)
12731273
progress.advance(task)
12741274

1275-
# This has to happen before compiling stateful components as that
1276-
# prevents recursive functions from reaching all components.
1277-
for component in self._pages.values():
1278-
# Add component._get_all_imports() to all_imports.
1279-
all_imports.update(component._get_all_imports())
1275+
with console.timing("Collect all imports and app wraps"):
1276+
# This has to happen before compiling stateful components as that
1277+
# prevents recursive functions from reaching all components.
1278+
for component in self._pages.values():
1279+
# Add component._get_all_imports() to all_imports.
1280+
all_imports.update(component._get_all_imports())
12801281

1281-
# Add the app wrappers from this component.
1282-
app_wrappers.update(component._get_all_app_wrap_components())
1282+
# Add the app wrappers from this component.
1283+
app_wrappers.update(component._get_all_app_wrap_components())
1284+
1285+
progress.advance(task)
12831286

12841287
# Perform auto-memoization of stateful components.
12851288
with console.timing("Auto-memoize StatefulComponents"):
12861289
(
12871290
stateful_components_path,
12881291
stateful_components_code,
12891292
page_components,
1290-
) = compiler.compile_stateful_components(self._pages.values())
1293+
) = compiler.compile_stateful_components(
1294+
self._pages.values(),
1295+
progress_function=lambda task=task: progress.advance(task),
1296+
)
12911297
progress.advance(task)
12921298

12931299
# Catch "static" apps (that do not define a rx.State subclass) which are trying to access rx.State.

reflex/compiler/compiler.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import sys
6-
from collections.abc import Iterable, Sequence
6+
from collections.abc import Callable, Iterable, Sequence
77
from inspect import getmodule
88
from pathlib import Path
99
from typing import TYPE_CHECKING
@@ -588,6 +588,7 @@ def compile_components(
588588

589589
def compile_stateful_components(
590590
pages: Iterable[Component],
591+
progress_function: Callable[[], None],
591592
) -> tuple[str, str, list[BaseComponent]]:
592593
"""Separately compile components that depend on State vars.
593594
@@ -597,14 +598,20 @@ def compile_stateful_components(
597598
598599
Args:
599600
pages: The pages to extract stateful components from.
601+
progress_function: A function to call to indicate progress, called once per page.
600602
601603
Returns:
602604
The path and code of the compiled stateful components.
603605
"""
604606
output_path = utils.get_stateful_components_path()
605607

606-
# Compile the stateful components.
607-
page_components = [StatefulComponent.compile_from(page) or page for page in pages]
608+
page_components = []
609+
for page in pages:
610+
# Compile the stateful components
611+
page_component = StatefulComponent.compile_from(page) or page
612+
progress_function()
613+
page_components.append(page_component)
614+
608615
code = _compile_stateful_components(page_components)
609616
return output_path, code, page_components
610617

0 commit comments

Comments
 (0)