Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark experimentation #4811

Merged
merged 5 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions reflex/compiler/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self) -> None:
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()}"
Expand Down
4 changes: 2 additions & 2 deletions tests/benchmarks/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
27 changes: 17 additions & 10 deletions tests/benchmarks/test_compilation.py
Original file line number Diff line number Diff line change
@@ -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())
13 changes: 9 additions & 4 deletions tests/benchmarks/test_evaluate.py
Original file line number Diff line number Diff line change
@@ -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)