Skip to content

DatePicker-Overlay opens very slow with large DOM [2 days] #8167

Closed
vaadin/web-components
#10380

Description

@MSCCSS

Description

When using the DatePicker on a Page with large and complex DOM, the overlay gets really slow. It opens and then takes multiple seconds to display most of its content.

chrome_performance_trace.json

Bildschirmaufnahme.2025-10-09.172544.mp4

Expected outcome

The DatePicker Overlay opens without any delay regardless of DOM size.

Minimal reproducible example

Example was tested within base-starter-gradle-24:

public MainView() {
        for (int k = 0; k < 10; k++) {
            for (int j = 0; j < 50; j++) {
                DatePicker datePicker = new DatePicker();
                Component last = null;
                for (int i = 0; i < 100; i++) {
                    Component current;
                    if (i % 2 == 0) {
                        current = new HorizontalLayout();
                        current.getElement().getStyle().set("height", "95%");
                        current.getElement().getStyle().set("width", "95%");
                    } else {
                        current = new VerticalLayout();
                        current.getElement().getStyle().set("flex-grow", "1");
                    }
                    current.getElement().getStyle().set("border", "1px solid black");
                    if (last instanceof HasComponents hasComponents) {
                        hasComponents.add(current);
                    } else {
                        add(current);
                    }
                    last = current;
                }
                ((HasComponents) last).add(datePicker);
            }
        }
    }

Steps to reproduce

Start the example (Or any other Project with large, complex DOM)
Click any DatePicker to open the Overlay.

Environment

Vaadin version(s): 24.9.1
OS: Windows 11

Browsers

Chrome

Activity

  1. TatuLund commented on Oct 20, 2025

    @TatuLund
    Contributor

    I couldn't import the recording with Chorme.

    Image

    The shared demo code attempts to create 50 000 layouts, which does not sound realistic. And actually on my computer the page wont even open. So I think better demo is required. When I reduced the number of layouts to 15 000 page opens and DatePicker opens a bit slowly, but not as slow as in video. The slowness in 15 000 layout scenario is expected and not even bad. I would assume that the real view in the video has considerably less elements than 15 000. So a bit better demo case that replicates the actual trigger for the poor performance would help us a lot to investigate.

  2. subITCSS commented on Oct 20, 2025

    @subITCSS

    So we tried to make it comprehensible cause our layout is a bit more complex and has a lot of flex-layouts and so on.
    In our application it looks like this:

    Issue_DatePickerOverlay.mp4
  3. TatuLund commented on Oct 20, 2025

    @TatuLund
    Contributor

    So we tried to make it comprehensible cause our layout is a bit more complex and has a lot of flex-layouts and so on.
    In our application it looks like this:

    If each line on that form is FlexLayout, there is only 7 and total number of elements in your view is around hundred, not 50 000 like in the demo code. The demo code is about something totally different than your actual case.

  4. TatuLund commented on Oct 20, 2025

    @TatuLund
    Contributor

    When opening the json file in https://www.speedscope.app/ it looks like the sloweness is distributed over several different JS calls, no single bottleneck. Was that recording made the demo code you shared or the real application?

    Image
  5. subITCSS commented on Oct 20, 2025

    @subITCSS

    I dont have that information but my guess is it is based on the base-gradle - the colleague who made this is recording on vacation this week.

  6. web-padawan commented on Oct 20, 2025

    @web-padawan
    Member

    The lines set active and above, up until _onOverlayOpened are indeed part of the date-picker overlay content.
    Is there any custom CSS that you apply to the date-picker overlay or any of its parts in your application?

  7. subITCSS commented on Oct 20, 2025

    @subITCSS

    Yes we have custom/additional styles for that - but i dont think these are heavy.
    Custom JS is not applied.

    For the vaadin-month-calendar we have these overrides:

    :host [part='date'][disabled],
    :host([part='date'][disabled]),
    :host([disabled]) * {
        color: var(--passive-color-50pct);
        -webkit-text-fill-color: var(--passive-color-50pct);
    }
    

    and for the vaadin-date-picker we have the following overrides:

    :host([theme~="grid-pro-editor"]) {
        align-items: center;
        display: flex;
        height: 100%;
        padding: 0 !important;
    }
    
    :host([theme~="grid-pro-editor"]) [part="input-field"] {
        height: 100%;
    }
    
    :host([theme~="date-picker-text-field"]) [part="helper-text"],
    :host([theme~="date-picker-text-field"]) [part="error-message"] {
        display: none;
    }
    
    :host([theme~="date-picker-text-field"]:not([theme~="schedule-calendar"])) [part="input-field"] {
        box-shadow: none !important;
        color: transparent;
        height: 85%;
        outline: none !important;
        user-select: none;
    }
    
    :host([theme~="schedule-calendar"]) [part="input-field"] {
        height: 100%;
    }
    
    :host([theme~="date-picker-text-field"][focused]) [part="toggle-button"],
    :host([theme~="date-picker-text-field"] [focused]) [part="toggle-button"] {
        border-radius: var(--field-roundness);
        outline: 2px var(--lumo-primary-color-10pct) !important;
        outline-offset: 5px;
    }
    
    :host([theme~="date-picker-text-field"]) [part="input-field"][slot="input"],
    :host([theme~="date-picker-text-field"]) [slot="input"],
    :host([theme~="date-picker-text-field"]) [part="input-field"] [slot="input"] {
        display: none !important;
    }
    
    :host([theme~="date-picker-text-field"]) [part="input-field"],
    :host([theme~="date-picker-text-field"]) [part="toggle-button"] {
        cursor: pointer;
    }
    
    :host([theme~="date-picker-text-field"][disabled]) [part="input-field"],
    :host([theme~="date-picker-text-field"][disabled]) [part="toggle-button"] {
        cursor: default;
    }
    
    :host([theme~="date-picker-text-field"]) .vaadin-date-picker-container {
        align-items: center;
        display: flex;
        justify-content: center;
        width: fit-content;
    }
    
    :host([theme~="date-picker-text-field"]) ::slotted(input) {
        padding: 0;
        display: none !important;
    }
    
    :host([focused]) [part=input-field] {
        box-shadow: none !important;
        outline: var(--focus-outline) !important;
        outline-offset: var(--focus-outline-inset);
    }
    
    :host([disabled]) [part='label'],
    :host([disabled]) [part='input-field'] ::slotted(*) {
        color: var(--passive-color-50pct);
        -webkit-text-fill-color: var(--passive-color-50pct);
    }
    
    :host([hasLabel]) {
        padding-top: 0;
    }
    
    :host([theme~="border"]:not([theme~="filled"])) [part='input-field'] {
        background-color: var(--lumo-base-color);
        box-shadow: inset 0 0 0 1px var(--input-field-border);
    }
    
    :host([theme~="border"]:hover:not([readonly]):not([focused])) [part='input-field']::after {
        opacity: 0;
    }
    
    :host([focused]) [part="input-field"] {
        box-shadow: none !important;
        outline: var(--focus-outline);
        outline-offset: var(--focus-outline-inset);
    }
    
    :host([invalid]) [part="input-field"] {
        outline: var(--focus-outline);
        outline-offset: var(--focus-outline-inset);
        outline-color: var(--lumo-error-color);
    }
    
    :host([theme~="grid-pro-editor"]) {
        height: 100%;
        padding: 0;
        --lumo-text-field-size: 100%;
    }
    
    :host([theme~="noBackground"][readonly]) [part="input-field"] {
        background-color: transparent;
    }
    
    :host([theme~="suffix"][readonly]) [part='input-field'] {
        background-color: var(--mass-edit-color) !important;
    }
    
    :host([theme~="mass-edit-border"][readonly]) [part='input-field'] {
        box-shadow: none !important;
        outline: var(--mass-edit-outline) !important;
        outline-offset: unset !important;
    }
    
    :host([theme~="border"][theme~=noBorder][readonly]) [part="input-field"] {
        box-shadow: none !important;
    
    }
    
    :host([theme~=noBorder]) [part="input-field"]::after {
        border: none;
    }
    
    :host([invalid][focused]) [part="label"] {
        color: var(--lumo-error-color);
    }
    
    :host([theme~="filled"]:not([disabled])[readonly]) [part='input-field'] {
        background-color: transparent !important;
    }
    
    :host([theme~="filled"][disabled]) [part="input-field"] {
        background-color: var(--lumo-contrast-5pct)
    }
    
    :host([readonly]) [part="input-field"]::after {
        border: none;
    }
    
    
    :host([disabled]) [part="input-field"],
    :host([readonly]) [part="input-field"] {
        background-color: var(--lumo-contrast-5pct);
        box-shadow: inset 1 0 0 1px var(--input-field-border);
    
    }
    
    :host([readonly]) [part="toggle-button"]::before,
    :host([disabled]) [part="toggle-button"]::before {
        content: "";
    }
    
    :host([theme~="grid-pro-editor"]) [part="input-field"] {
        flex-grow: 1;
    }
    
    :host([theme~="success"][theme~="noBackground"][readonly]) [part="input-field"],
    :host([theme~="success"][theme~="border"]) [part="input-field"],
    :host([theme~="success"]) [part="input-field"] {
        background-color: var(--lumo-success-color-10pct);
        color: var(--passive-color-80pct);
    }
    
    :host([theme~="error"][theme~="noBackground"][readonly]) [part="input-field"],
    :host([theme~="error"][theme~="border"]) [part="input-field"],
    :host([theme~="error"]) [part="input-field"] {
        background-color: var(--lumo-error-color-10pct);
        color: var(--passive-color-80pct);
    }
    
    :host([theme~="warning"][theme~="noBackground"][readonly]) [part="input-field"],
    :host([theme~="warning"][theme~="border"]) [part="input-field"],
    :host([theme~="warning"]) [part="input-field"] {
        background-color: var(--warning-color-10pct);
        color: var(--passive-color-80pct);
    }
    
    :host([theme~="info"][theme~="noBackground"][readonly]) [part="input-field"],
    :host([theme~="info"][theme~="border"]) [part="input-field"],
    :host([theme~="info"]) [part="input-field"] {
        background-color: var(--info-color-10pct);
        color: var(--lumo-base-color);
    }
    
    :host([theme~="primary"][theme~="noBackground"][readonly]) [part="input-field"],
    :host([theme~="primary"][theme~="border"]) [part="input-field"],
    :host([theme~="primary"]) [part="input-field"] {
        background-color: var(--lumo-primary-color-10pct);
        color: var(--passive-color-80pct);
    }
    
    :host([theme~="secondary"][theme~="noBackground"][readonly]) [part="input-field"],
    :host([theme~="secondary"][theme~="border"]) [part="input-field"],
    :host([theme~="secondary"]) [part="input-field"] {
        background-color: var(--passive-color-10pct);
        color: var(--lumo-tertiary-color-80pct);
    }
    
    :host([theme~="tertiary"][theme~="noBackground"][readonly]) [part="input-field"],
    :host([theme~="tertiary"][theme~="border"]) [part="input-field"],
    :host([theme~="tertiary"]) [part="input-field"] {
        background-color: transparent;
        color: var(--lumo-tertiary-color-80pct);
    }
    
    :host([required]) [part="required-indicator"]::after {
        color: var(--lumo-error-color);
        content: var(--lumo-required-field-indicator, "*");
    }
    
    :host [part="error-message"],
    :host [part="helper-text"] {
        font-size: var(--lumo-font-size-xxs);
    }
    
    :host [part="input-field"] ::-moz-selection,
    :host ::-moz-selection {
        background: var(--selection-background-color);
        color: var(--selection-color);
    }
    
    :host [part="input-field"] ::selection,
    :host ::selection {
        background: var(--selection-background-color);
        color: var(--selection-color);
    }
    
    :host [part='input-field'] {
        border-radius: var(--field-roundness);
        font-size: var(--iphone-font-size, var(--lumo-font-size-m));
        overflow: hidden;
    }
    
    :host([theme~="info-border"]) [part="input-field"] {
        background: var(--info-color-20pct) !important;
        box-shadow: inset 0 0 0 1px var(--info-color) !important;
    }
    
    :host [part="error-message"] {
        transition: unset;
        position: relative;
        height: 0;
    }
    
    :host ::slotted([slot="error-message"]) {
        position: absolute;
        transform: translateY(-50%);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
        top: 0.5rem;
    }
    
    :host([has-helper]) ::slotted([slot="error-message"]) {
        top: 0.4rem;
    }
    
  8. nicofri-css commented on Oct 20, 2025

    @nicofri-css

    We were able to solve the problem. The cause of the long loading time was a few global CSS selectors (CSS Universal (*) and :has selectors), which multiplied with the "Recalculate Styles" after the _isVisible call (marked in the image). Nevertheless, an analysis of the many _isVisible calls would be useful. These calls can also be reproduced in a base gradle starter. To do this, simply add a date picker to the view and open it.

    Image
  9. web-padawan commented on Oct 20, 2025

    @web-padawan
    Member

    Here is the relevant logic of _isVisible() and its invocation in _createPool(). The logic of vaadin-infinite-scroller hasn't really changed lately. We could try to investigate this further to see if there is some room for improvement.

  10. jouni commented on Oct 22, 2025

    @jouni
    Member

    I’ve been noticing similar slowness in the Aura dev/demo page: https://vaadin.github.io/web-components/aura.html

    Screen.Recording.2025-10-22.at.11.28.45.mov

    Could definitely be faster to render.

  11. changed the title [-]DatePicker-Overlay opens very slow with large DOM[/-] [+]DatePicker-Overlay opens very slow with large DOM [2 days][/+] on Oct 22, 2025
  12. web-padawan commented on Oct 22, 2025

    @web-padawan
    Member

    In V14 version of the date-picker, we used to have extra setTimeout() calls around some invocations - example.
    IIRC, originally this was done to deal with IE11 and polyfills, but it might be worth checking if restoring that helps.

  13. self-assigned this
    on Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions