Avaiga / taipy

Turns Data and AI algorithms into production-ready web applications in no time.
https://www.taipy.io
Apache License 2.0
16.99k stars 1.86k forks source link

Performance issue when using scenario viz elements #1543

Closed FlorianJacta closed 4 months ago

FlorianJacta commented 4 months ago

Description

Using many scenario viz elements, like scenario selectors, will slow down the page's rendering. In real cases, this loading on my local machine took some seconds.

This could stop the adoption of scenario viz elements for the community.

We should aim to make loading times faster and improve the performance when using scenario viz elements.

Here is a small example that tries to showcase this behavior. That might not work on your local machine.

# Import necessary libraries
import pandas as pd
import taipy as tp
from taipy import Config, Scope, Frequency

import datetime as dt

# Function to run a Dataiku scenario
def run_something(**kwargs):
    datetime = dt.datetime.now()
    date = dt.date(2018, 1, 1)
    int_var = 10
    string_var = "String"
    return kwargs

data = {"toto": [i for i in range(10_000)], 
        "titi": [2*i for i in range(10_000)],
        "tata": [4*i for i in range(10_000)]}

def create_dn(id):
    return Config.configure_data_node(id=id, default_data=data)

# Scenario and task configuration in Taipy
scenario_task_cfg = Config.configure_task(
    id="scenario_task",
    function=run_something,
    input=[create_dn(f"input_datanode_{i}") for i in range(10)],
    output=[create_dn(f"output_datanode_{i}") for i in range(10)]
)

scenario_cfg = Config.configure_scenario(
    id="scenario",
    task_configs=[scenario_task_cfg],
    frequency=Frequency.MONTHLY)

scenario_1 = None
scenario_2 = None

data_node = None

# GUI Markdown content
scenario_md = """
<|navbar|>

# Compare scenarios
<|1 1|layout|
<|{scenario_1}|scenario_selector|>

<|{scenario_2}|scenario_selector|>

<|{scenario_1}|scenario|>

<|{scenario_2}|scenario|>
|>

# Data Nodes

<|1 1|layout|
<|{data_node}|data_node_selector|>

<|{data_node}|data_node|>
|>

""" 

pages = {"home":"<|navbar|> Nothing here",
         "vizelements":scenario_md}

# Main execution block with GUI setup
if __name__ == "__main__":
    tp.Core().run()
    [tp.create_scenario(scenario_cfg, 
                        name=f"scenario_{i}", 
                        creation_date=dt.datetime(2024, i, 7)) 
                    for i in range(1, 11)]

    tp.Gui(pages=pages).run(title="Bug replication", port=3248)

Acceptance Criteria

Code of Conduct

FredLL-Avaiga commented 4 months ago

I've improved a bit by removing the calculation of default value of the lov of selectors but it doesn't gain much (nothing really visible on my PC.

https://github.com/user-attachments/assets/d7158a0a-6d47-4a47-ac9a-c972d16684d6

App Startup is quite long

[2024-07-27 16:27:05.078][Taipy][INFO] Updating configuration with command-line arguments...
[2024-07-27 16:27:05.079][Taipy][INFO] Managing application's version...
[2024-07-27 16:27:05.080][Taipy][INFO] Development mode: Clean all entities of version 0880e210-eb76-490c-ba8e-09488dc49586
[2024-07-27 16:27:34.141][Taipy][INFO] Checking application's version...
[2024-07-27 16:27:34.144][Taipy][INFO] Blocking configuration update...
[2024-07-27 16:27:34.144][Taipy][INFO] Starting job dispatcher...
[2024-07-27 16:27:34.145][Taipy][INFO] Core service has been started.
[2024-07-27 16:27:42.331][Taipy][INFO] 'allow_unsafe_werkzeug' has been set to True
[2024-07-27 16:27:42.332][Taipy][INFO] 'async_mode' parameter has been overridden to 'threading'. Using Flask built-in development server with debug mode
[2024-07-27 16:27:44.918][Taipy][INFO]  * Server starting on http://127.0.0.1:5000