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

Schemapi debug mode always on? #2850

Closed
velochy opened this issue Jan 23, 2023 · 4 comments
Closed

Schemapi debug mode always on? #2850

velochy opened this issue Jan 23, 2023 · 4 comments

Comments

@velochy
Copy link

velochy commented Jan 23, 2023

I was debugging some performance issues in my streamlit application and noticed that Altair schema validation is taking a significant amount of rendering time.

So I dug into the altair code and noticed something rather odd in altair/utils/schemapi.py, row 23-33

DEBUG_MODE = True


def enable_debug_mode():
    global DEBUG_MODE
    DEBUG_MODE = True


def disable_debug_mode():
    global DEBUG_MODE
    DEBUG_MODE = True

So if I read it correctly, debug mode is set by default, and "disable_debug_mode()" will fail to disable it.

Its hard to believe this is intended behavior, but I'd prefer someone who understand the codebase better have a look.

@binste
Copy link
Contributor

binste commented Jan 23, 2023

Thanks for reporting this! Having DEBUG_MODE = True is actually the intended behaviour when it was introduced in #546, see that PR for the reasoning but it's about providing more informative error messages. I think the name DEBUG_MODE is maybe a bit unfortunate.

disable_debug_mode should definitely set it to False, that's a bug which should be fixed.

I proposed a rework of the validation over at #2842 and I'm wondering if we still need this validation upon creation of objects. The error messages are now informative without it so that's no longer a relevant concern but it provides error messages sooner when you create certain objects before you display them which can be nice. @velochy Do you have any performance measurements you can share? I'd very much appreciate this to get a better understanding of how much this feature slows users down. What do you mean with "significant amount of rendering time"? How does this compare to setting DEBUG_MODE = False?

@binste
Copy link
Contributor

binste commented Jan 23, 2023

I used the %%timeit cell magic in Jupyter to time the following example. With DEBUG_MODE = True it takes 12.2 ms ± 499 µs per loop (mean ± std. dev. of 7 runs, 100 loops each). If set to False, I get 8.22 ms ± 250 µs per loop (mean ± std. dev. of 7 runs, 100 loops each). This is a difference which should not be noticeable for a user.

stocks = data.stocks.url
highlight = alt.selection_point(name="highlight", on="mouseover", clear="mouseout")

line = (
    alt.Chart(height=100, width=200)
    .mark_line(point=True)
    .encode(x=alt.X("date:N", timeUnit="year"), y=alt.Y("mean(price):Q"))
)

rect = (
    alt.Chart(width=200)
    .mark_rect()
    .encode(
        x=alt.X("date:T", timeUnit="year"),
        fill=alt.Y("mean(price):Q"),
        stroke=alt.condition(
            highlight, alt.value("black"), alt.value(None), empty=False
        ),
    )
    .add_params(highlight)
)

alt.vconcat(line, rect, data=stocks)

The advantage of the immediate validation with DEBUG_MODE = True is that errors can be catched earlier. If I for example introduce an argument unknown to selection_point I'd immediately get the correct error without having to wait for the chart to be rendered:

highlight = alt.selection_point(name="highlight", on="mouseover", clear="mouseout", unknown="test")
altair.vegalite.v5.schema.core.PointSelectionConfig, validating 'additionalProperties'

        Additional properties are not allowed ('unknown' was unexpected)

@mattijn
Copy link
Contributor

mattijn commented Jan 23, 2023

I think you mean #2842 and not #2824 for the rework of the validation.

@binste
Copy link
Contributor

binste commented Jan 23, 2023

Indeed, thanks! Edited my comment.

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

No branches or pull requests

3 participants