From 7a09554cfadd8a895c4325b0da0c55947594fb5c Mon Sep 17 00:00:00 2001 From: jackie-pc <136611113+jackie-pc@users.noreply.github.com> Date: Wed, 26 Jul 2023 16:04:48 -0700 Subject: [PATCH] dev-mode compile: purge .web dir at last min to reduce downtime window (#1430) --- .gitignore | 3 ++- .pre-commit-config.yaml | 1 + reflex/app.py | 12 ++++++++---- reflex/utils/imports.py | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 1a06add81..171b380a7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ dist/* examples/ .idea .vscode -.coverage \ No newline at end of file +.coverage +venv \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 70e42bd77..211cb4d5e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,6 +3,7 @@ repos: rev: v0.0.244 hooks: - id: ruff + args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/RobertCraigie/pyright-python rev: v1.1.313 diff --git a/reflex/app.py b/reflex/app.py index a9f2487e0..10928d6c9 100644 --- a/reflex/app.py +++ b/reflex/app.py @@ -467,23 +467,23 @@ class App(Base): ) task = progress.add_task("Compiling: ", total=len(self.pages)) + # TODO: include all work done in progress indicator, not just self.pages for render, kwargs in DECORATED_ROUTES: self.add_page(render, **kwargs) # Get the env mode. config = get_config() - # Empty the .web pages directory - compiler.purge_web_pages_dir() - # Store the compile results. compile_results = [] # Compile the pages in parallel. custom_components = set() + # TODO Anecdotally, processes=2 works 10% faster (cpu_count=12) thread_pool = ThreadPool() with progress: for route, component in self.pages.items(): + # TODO: this progress does not reflect actual threaded task completion progress.advance(task) component.add_style(self.style) compile_results.append( @@ -505,6 +505,8 @@ class App(Base): # Get the results. compile_results = [result.get() for result in compile_results] + # TODO the compile tasks below may also benefit from parallelization too + # Compile the custom components. compile_results.append(compiler.compile_components(custom_components)) @@ -521,10 +523,12 @@ class App(Base): ) compile_results.append(compiler.compile_tailwind(config.tailwind)) + # Empty the .web pages directory + compiler.purge_web_pages_dir() + # Write the pages at the end to trigger the NextJS hot reload only once. thread_pool = ThreadPool() for output_path, code in compile_results: - compiler_utils.write_page(output_path, code) thread_pool.apply_async(compiler_utils.write_page, args=(output_path, code)) thread_pool.close() thread_pool.join() diff --git a/reflex/utils/imports.py b/reflex/utils/imports.py index 34e89c2ca..62d66a9c4 100644 --- a/reflex/utils/imports.py +++ b/reflex/utils/imports.py @@ -9,7 +9,7 @@ ImportDict = Dict[str, Set[ImportVar]] def merge_imports(*imports) -> ImportDict: - """Merge two import dicts together. + """Merge multiple import dicts together. Args: *imports: The list of import dicts to merge.