Add timing for other app._compile events

This commit is contained in:
Masen Furer 2025-02-06 11:17:56 -08:00
parent 8e3962426e
commit f8eba338e0
No known key found for this signature in database
GPG Key ID: B0008AD22B3B3A95

View File

@ -999,9 +999,10 @@ class App(MiddlewareMixin, LifespanMixin):
should_compile = self._should_compile() should_compile = self._should_compile()
if not should_compile: if not should_compile:
for route in self._unevaluated_pages: with console.timing("Evaluate Pages (Backend)"):
console.debug(f"Evaluating page: {route}") for route in self._unevaluated_pages:
self._compile_page(route, save_page=should_compile) console.debug(f"Evaluating page: {route}")
self._compile_page(route, save_page=should_compile)
# Add the optional endpoints (_upload) # Add the optional endpoints (_upload)
self._add_optional_endpoints() self._add_optional_endpoints()
@ -1027,10 +1028,11 @@ class App(MiddlewareMixin, LifespanMixin):
+ adhoc_steps_without_executor, + adhoc_steps_without_executor,
) )
for route in self._unevaluated_pages: with console.timing("Evaluate Pages (Frontend)"):
console.debug(f"Evaluating page: {route}") for route in self._unevaluated_pages:
self._compile_page(route, save_page=should_compile) console.debug(f"Evaluating page: {route}")
progress.advance(task) self._compile_page(route, save_page=should_compile)
progress.advance(task)
# Add the optional endpoints (_upload) # Add the optional endpoints (_upload)
self._add_optional_endpoints() self._add_optional_endpoints()
@ -1065,13 +1067,13 @@ class App(MiddlewareMixin, LifespanMixin):
custom_components |= component._get_all_custom_components() custom_components |= component._get_all_custom_components()
# Perform auto-memoization of stateful components. # Perform auto-memoization of stateful components.
( with console.timing("Auto-memoize StatefulComponents"):
stateful_components_path, (
stateful_components_code, stateful_components_path,
page_components, stateful_components_code,
) = compiler.compile_stateful_components(self._pages.values()) page_components,
) = compiler.compile_stateful_components(self._pages.values())
progress.advance(task) progress.advance(task)
# Catch "static" apps (that do not define a rx.State subclass) which are trying to access rx.State. # Catch "static" apps (that do not define a rx.State subclass) which are trying to access rx.State.
if code_uses_state_contexts(stateful_components_code) and self._state is None: if code_uses_state_contexts(stateful_components_code) and self._state is None:
@ -1154,9 +1156,10 @@ class App(MiddlewareMixin, LifespanMixin):
_submit_work(compiler.remove_tailwind_from_postcss) _submit_work(compiler.remove_tailwind_from_postcss)
# Wait for all compilation tasks to complete. # Wait for all compilation tasks to complete.
for future in concurrent.futures.as_completed(result_futures): with console.timing("Compile to Javascript"):
compile_results.append(future.result()) for future in concurrent.futures.as_completed(result_futures):
progress.advance(task) compile_results.append(future.result())
progress.advance(task)
app_root = self._app_root(app_wrappers=app_wrappers) app_root = self._app_root(app_wrappers=app_wrappers)
@ -1191,7 +1194,8 @@ class App(MiddlewareMixin, LifespanMixin):
progress.stop() progress.stop()
# Install frontend packages. # Install frontend packages.
self._get_frontend_packages(all_imports) with console.timing("Install Frontend Packages"):
self._get_frontend_packages(all_imports)
# Setup the next.config.js # Setup the next.config.js
transpile_packages = [ transpile_packages = [
@ -1217,8 +1221,9 @@ class App(MiddlewareMixin, LifespanMixin):
# Remove pages that are no longer in the app. # Remove pages that are no longer in the app.
p.unlink() p.unlink()
for output_path, code in compile_results: with console.timing("Write to Disk"):
compiler_utils.write_page(output_path, code) for output_path, code in compile_results:
compiler_utils.write_page(output_path, code)
@contextlib.asynccontextmanager @contextlib.asynccontextmanager
async def modify_state(self, token: str) -> AsyncIterator[BaseState]: async def modify_state(self, token: str) -> AsyncIterator[BaseState]: