diff --git a/reflex/compiler/templates.py b/reflex/compiler/templates.py index 117b655a93..e85e5fe6df 100644 --- a/reflex/compiler/templates.py +++ b/reflex/compiler/templates.py @@ -48,11 +48,10 @@ class ReflexJinjaEnvironment(Environment): def __init__(self) -> None: """Set default environment.""" - extensions = ["jinja2.ext.debug"] super().__init__( - extensions=extensions, trim_blocks=True, lstrip_blocks=True, + auto_reload=False, ) self.filters["json_dumps"] = json_dumps self.filters["react_setter"] = lambda state: f"set{state.capitalize()}" diff --git a/tests/benchmarks/fixtures.py b/tests/benchmarks/fixtures.py index 16233100ad..334d48282a 100644 --- a/tests/benchmarks/fixtures.py +++ b/tests/benchmarks/fixtures.py @@ -374,10 +374,10 @@ def _stateful_page(): @pytest.fixture(params=[_simple_page, _complicated_page, _stateful_page]) -def unevaluated_page(request): +def unevaluated_page(request: pytest.FixtureRequest): return request.param @pytest.fixture(params=[_simple_page, _complicated_page, _stateful_page]) -def evaluated_page(request): +def evaluated_page(request: pytest.FixtureRequest): return request.param() diff --git a/tests/benchmarks/test_compilation.py b/tests/benchmarks/test_compilation.py index 0a20ed5216..dbea810239 100644 --- a/tests/benchmarks/test_compilation.py +++ b/tests/benchmarks/test_compilation.py @@ -1,18 +1,25 @@ -import pytest +from pytest_codspeed import BenchmarkFixture from reflex.compiler.compiler import _compile_page, _compile_stateful_components +from reflex.components.component import Component -@pytest.mark.benchmark -def test_compile_page(evaluated_page): - _compile_page(evaluated_page, None) +def import_templates(): + # Importing the templates module to avoid the import time in the benchmark + import reflex.compiler.templates # noqa: F401 -@pytest.mark.benchmark -def test_compile_stateful(evaluated_page): - _compile_stateful_components([evaluated_page]) +def test_compile_page(evaluated_page: Component, benchmark: BenchmarkFixture): + import_templates() + benchmark(lambda: _compile_page(evaluated_page, None)) -@pytest.mark.benchmark -def test_get_all_imports(evaluated_page): - evaluated_page._get_all_imports() + +def test_compile_stateful(evaluated_page: Component, benchmark: BenchmarkFixture): + import_templates() + + benchmark(lambda: _compile_stateful_components([evaluated_page])) + + +def test_get_all_imports(evaluated_page: Component, benchmark: BenchmarkFixture): + benchmark(lambda: evaluated_page._get_all_imports()) diff --git a/tests/benchmarks/test_evaluate.py b/tests/benchmarks/test_evaluate.py index fbc75dea70..7fd75fc6c9 100644 --- a/tests/benchmarks/test_evaluate.py +++ b/tests/benchmarks/test_evaluate.py @@ -1,6 +1,11 @@ -import pytest +from typing import Callable +from pytest_codspeed import BenchmarkFixture -@pytest.mark.benchmark -def test_evaluate_page(unevaluated_page): - unevaluated_page() +from reflex.components.component import Component + + +def test_evaluate_page( + unevaluated_page: Callable[[], Component], benchmark: BenchmarkFixture +): + benchmark(unevaluated_page)