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

Speedup startup and reload time of 24.4 #19112

Open
tltv opened this issue Apr 5, 2024 · 0 comments
Open

Speedup startup and reload time of 24.4 #19112

tltv opened this issue Apr 5, 2024 · 0 comments
Assignees

Comments

@tltv
Copy link
Member

tltv commented Apr 5, 2024

Describe your motivation

Spring application start up time has increased with 24.4 compared to 24.3 when using Hilla and Copilot. It's increased even when not actually using Hilla. Just having dependencies in the classpath is enough to slow down startup time and also reload time.

Describe the solution you'd like

Speed up startup time and reload time of Vaadin 24.4 Spring application. More information on how to do that in #18812.

Proposed solution is to add following in the VaadinServletContextInitializer#CustomResourceLoader to filter jars that are not needed to be read file-by-file by the class scanner:

        @Override
        protected Set<Resource> doFindPathMatchingJarResources(Resource rootDirResource, URL rootDirUrl, String subPattern) throws IOException {
            String path = rootDirResource.getURI().toString();
            if(DEFAULT_SCAN_NEVER_JAR.stream().anyMatch(path::contains)) {
                return Set.of();
            }
            return super.doFindPathMatchingJarResources(rootDirResource, rootDirUrl, subPattern);
        }

        @Override
        protected Set<Resource> doFindAllClassPathResources(String path) throws IOException {
            var result = super.doFindAllClassPathResources(path);
            result.removeIf(res -> {
                try {
                    return DEFAULT_SCAN_NEVER_JAR.stream()
                            .anyMatch(res.getURI().toString()::contains);
                } catch (IOException e) {
                    return false;
                }
            });
            return result;
        }

Describe alternatives you've considered

Just excluding Hilla dependencies speeds up start time, but not to the same level as with 24.3.

Additional context

#18812

tltv added a commit that referenced this issue Apr 5, 2024
Filter "com/vaadin/hilla" and "com/vaadin/copilot" packages by default from the class scanner in VaadinServletContextInitializer and include only what is really needed: com.vaadin.copilot.CopilotIndexHtmlLoader, com.vaadin.copilot.CopilotLoader and com.vaadin.hilla.startup. This speeds up mostly reload time and also startup time a bit.

Related-to: #19112
caalador pushed a commit that referenced this issue Apr 12, 2024
Filter "com/vaadin/hilla" and "com/vaadin/copilot" packages by default from the class scanner in VaadinServletContextInitializer and include only what is really needed: com.vaadin.copilot.startup and com.vaadin.hilla.startup. This speeds up mostly reload time and also startup time a bit.

Related-to: #19112
@tltv tltv self-assigned this May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ⚒️ In progress
Development

No branches or pull requests

1 participant