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

rxui.vmodel executes slowly #174

Open
CrystalWindSnake opened this issue Mar 21, 2024 · 1 comment
Open

rxui.vmodel executes slowly #174

CrystalWindSnake opened this issue Mar 21, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@CrystalWindSnake
Copy link
Owner

from nicegui import ui
from ex4nicegui import deep_ref, rxui
from ex4nicegui.utils.signals import to_ref_wrapper
import time


def calculate_execution_time(func):
    def wrapper(*args, **kwargs):
        start_time = time.time()
        result = func(*args, **kwargs)
        end_time = time.time()
        print(
            f"Function '{func.__name__}' took {end_time - start_time} seconds to execute."
        )
        return result

    return wrapper


@calculate_execution_time
def use_vmodel():
    data = deep_ref({"a": "text"})

    rxui.label(data)
    rxui.input(value=rxui.vmodel(data.value["a"]))


use_vmodel()


@calculate_execution_time
def use_to_wrap():
    data = deep_ref({"a": "text"})

    def setter(new_value):
        data.value["a"] = new_value

    wrapper = to_ref_wrapper(lambda: data.value["a"], setter)

    rxui.label(data)
    rxui.input(value=wrapper)


use_to_wrap()

ui.run()

Using rxui.vmodel is much slower than using to_ref_wrapper

Function 'use_vmodel' took 0.6890246868133545 seconds to execute.
Function 'use_to_wrap' took 0.0 seconds to execute.
@CrystalWindSnake CrystalWindSnake added the enhancement New feature or request label Mar 21, 2024
@CrystalWindSnake
Copy link
Owner Author

Inefficient execution due to vmodel needing to fetch the caller's previous frame.
Consider adding a new type of binding

data = deep_ref({"a": "text"})
rxui.input(value=rxui.two_way_binding(data.value,'a'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant