From 03c5ca255edfee9633d8f960b14110bd34ffb4f7 Mon Sep 17 00:00:00 2001 From: Farhan Date: Thu, 17 Sep 2026 22:52:33 +0500 Subject: [PATCH 1/3] bench: drop flaky isinstance, event handler, and compiler import benchmarks Remove test_isinstance_container[list_dict], test_from_event_type[event_handler], test_get_all_imports and test_collect_imports, whose _complicated_page variants flag noise as regressions. The remaining compile benchmarks still walk imports, and test_import_reflex keeps measuring cold import time. --- tests/benchmarks/fixtures.py | 53 +------------------------ tests/benchmarks/test_compilation.py | 38 ------------------ tests/benchmarks/test_event_creation.py | 6 +-- tests/benchmarks/test_isinstance.py | 2 - 4 files changed, 3 insertions(+), 96 deletions(-) diff --git a/tests/benchmarks/fixtures.py b/tests/benchmarks/fixtures.py index f5afda90746..ff3d2c10b69 100644 --- a/tests/benchmarks/fixtures.py +++ b/tests/benchmarks/fixtures.py @@ -1,14 +1,10 @@ -from collections.abc import Callable from dataclasses import dataclass -from typing import Any, cast +from typing import cast import pytest from pydantic import BaseModel -from reflex_base.components.component import BaseComponent, Component -from reflex_base.plugins import CompileContext, PageContext import reflex as rx -from reflex.compiler.plugins import DefaultCollectorPlugin class SideBarState(rx.State): @@ -225,53 +221,6 @@ class NestedElement(BaseModel): value: list[int] -@dataclass(frozen=True, slots=True) -class ImportOnlyCollectorPlugin(DefaultCollectorPlugin): - """Collect only imports — same scope as Component._get_all_imports. - - Inherits import collection from DefaultCollectorPlugin but disables - hooks, custom code, app_wrap, and stateful code rendering. - """ - - _compiler_stateful_only_leave_component = False - - def leave_component(self, *_args: Any, **_kwargs: Any) -> None: - """No-op: skip stateful code rendering.""" - - def _compiler_bind_leave_component( - self, *_args: Any, **_kwargs: Any - ) -> Callable[..., None]: - """Return a no-op leave hook.""" - - def _noop(*_a: Any, **_kw: Any) -> None: - pass - - return _noop - - def _compiler_bind_enter_component( - self, - page_context: PageContext, - compile_context: CompileContext, - ) -> Callable[[BaseComponent, bool], None]: - del compile_context - - frontend_imports = page_context.frontend_imports - extend_imports = self._extend_imports - - def enter_component( - comp: BaseComponent, - in_prop_tree: bool, - ) -> None: - if not isinstance(comp, Component) or in_prop_tree: - return - - imports = comp._get_imports() - if imports: - extend_imports(frontend_imports, imports) - - return enter_component - - @dataclass class Order: """An order in the table event benchmark.""" diff --git a/tests/benchmarks/test_compilation.py b/tests/benchmarks/test_compilation.py index af084860859..8d38ae3a7df 100644 --- a/tests/benchmarks/test_compilation.py +++ b/tests/benchmarks/test_compilation.py @@ -9,8 +9,6 @@ from reflex.compiler.plugins import DefaultCollectorPlugin, default_page_plugins from reflex.compiler.plugins.memoize import MemoizeStatefulPlugin -from .fixtures import ImportOnlyCollectorPlugin - def import_templates(): # Importing the templates module to avoid the import time in the benchmark @@ -42,31 +40,6 @@ def _compile_page_context(component: Component) -> PageContext: return page_ctx -def _collect_imports(component: Component) -> dict: - """Collect only imports via a single walk of the component tree. - - Returns: - The collapsed import dict for the page. - """ - page_ctx = PageContext( - name="benchmark", - route="/benchmark", - root_component=component, - ) - hooks = CompilerHooks(plugins=(ImportOnlyCollectorPlugin(),)) - compile_ctx = CompileContext(pages=[], hooks=hooks) - - with compile_ctx, page_ctx: - hooks.compile_component( - component, - page_context=page_ctx, - compile_context=compile_ctx, - ) - hooks.compile_page(page_ctx, compile_context=compile_ctx) - - return page_ctx.frontend_imports - - def _compile_page(component: Component) -> str: page_ctx = _compile_page_context(component) page_ctx.frontend_imports = page_ctx.merged_imports(collapse=True) @@ -108,17 +81,6 @@ def test_compile_page_full_context( benchmark(lambda: _compile_page_full_context(unevaluated_page)) -def test_get_all_imports(evaluated_page: Component, benchmark: BenchmarkFixture): - benchmark(lambda: evaluated_page._get_all_imports()) - - -def test_collect_imports( - evaluated_page: Component, - benchmark: BenchmarkFixture, -): - benchmark(lambda: _collect_imports(evaluated_page)) - - def test_compile_all_artifacts( evaluated_page: Component, benchmark: BenchmarkFixture, diff --git a/tests/benchmarks/test_event_creation.py b/tests/benchmarks/test_event_creation.py index ea09a3f3fc2..a814f0d2c20 100644 --- a/tests/benchmarks/test_event_creation.py +++ b/tests/benchmarks/test_event_creation.py @@ -60,7 +60,6 @@ def increment_event(increment_spec: EventSpec) -> Event: params=( "event", "event_spec", - "event_handler", "lambda_event", "lambda_event_spec", "lambda_event_handler", @@ -89,7 +88,6 @@ def event_input( inputs: dict[str, Any] = { "event": increment_event, "event_spec": increment_spec, - "event_handler": increment_handler, "lambda_event": lambda: increment_event, "lambda_event_spec": lambda: increment_spec, "lambda_event_handler": lambda: increment_handler, @@ -100,8 +98,8 @@ def event_input( def test_from_event_type(event_input: Any, benchmark: BenchmarkFixture): """Benchmark ``Event.from_event_type`` for each supported input shape. - Covers existing Event, EventSpec (from calling EventHandler), EventHandler, - and lambdas returning each of those — the common shapes encountered + Covers existing Event, EventSpec (from calling EventHandler), and lambdas + returning an Event, EventSpec, or EventHandler — the common shapes encountered when normalizing user-returned event values. Args: diff --git a/tests/benchmarks/test_isinstance.py b/tests/benchmarks/test_isinstance.py index cac451f5d8a..8204a9b871e 100644 --- a/tests/benchmarks/test_isinstance.py +++ b/tests/benchmarks/test_isinstance.py @@ -22,7 +22,6 @@ class _Element(TypedDict): _INTS = list(range(N)) -_DICTS = [{"a": 1, "b": 2} for _ in range(N)] _OPTIONALS = [1, None] * (N // 2) _ELEMENTS: list[_Element] = [{"x": 1, "y": "s"} for _ in range(N)] @@ -31,7 +30,6 @@ class _Element(TypedDict): ("obj", "hint"), [ pytest.param(_INTS, list[int], id="list_int"), - pytest.param(_DICTS, list[dict[str, int]], id="list_dict"), pytest.param(_OPTIONALS, list[int | None], id="list_optional"), pytest.param(_ELEMENTS, list[_Element], id="list_typeddict"), ], From f16d35f124d45b2af852ac22e3932643519b21ec Mon Sep 17 00:00:00 2001 From: Farhan Date: Fri, 18 Sep 2026 01:00:08 +0500 Subject: [PATCH 2/3] bench: drop the flaky lambda_event from_event_type param Unrelated PRs (#7175, #7188) moved it by 3-4% in simulation mode. The event param covers the Event pass-through branch and the remaining lambda params cover the lambda unwrapping branch. --- tests/benchmarks/test_event_creation.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/benchmarks/test_event_creation.py b/tests/benchmarks/test_event_creation.py index a814f0d2c20..e4612d96ffa 100644 --- a/tests/benchmarks/test_event_creation.py +++ b/tests/benchmarks/test_event_creation.py @@ -60,7 +60,6 @@ def increment_event(increment_spec: EventSpec) -> Event: params=( "event", "event_spec", - "lambda_event", "lambda_event_spec", "lambda_event_handler", ) @@ -88,7 +87,6 @@ def event_input( inputs: dict[str, Any] = { "event": increment_event, "event_spec": increment_spec, - "lambda_event": lambda: increment_event, "lambda_event_spec": lambda: increment_spec, "lambda_event_handler": lambda: increment_handler, } From 02ab2c59f9ba2a3fd32433df3dacb08cbfb094b4 Mon Sep 17 00:00:00 2001 From: Farhan Date: Fri, 18 Sep 2026 01:20:21 +0500 Subject: [PATCH 3/3] bench: drop the flaky lambda_event_spec from_event_type param It drifted 3-4% on #7175 and #7188 with no event code changed. It is the event_spec path plus one lambda call, which lambda_event_handler already covers. --- tests/benchmarks/test_event_creation.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/benchmarks/test_event_creation.py b/tests/benchmarks/test_event_creation.py index e4612d96ffa..0a1f6ff4447 100644 --- a/tests/benchmarks/test_event_creation.py +++ b/tests/benchmarks/test_event_creation.py @@ -60,7 +60,6 @@ def increment_event(increment_spec: EventSpec) -> Event: params=( "event", "event_spec", - "lambda_event_spec", "lambda_event_handler", ) ) @@ -87,7 +86,6 @@ def event_input( inputs: dict[str, Any] = { "event": increment_event, "event_spec": increment_spec, - "lambda_event_spec": lambda: increment_spec, "lambda_event_handler": lambda: increment_handler, } return inputs[request.param]