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

Closed
tltv opened this issue Apr 5, 2024 · 1 comment · Fixed by #19395
Closed

Speedup startup and reload time of 24.4 #19112

tltv opened this issue Apr 5, 2024 · 1 comment · Fixed by #19395

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
tltv added a commit that referenced this issue May 16, 2024
Optimize class scanning of VaadinServletContextInitializer by excluding some commonly used jars and add support for vaadin.blocked-jar boolean property in META-INF/VAADIN/package.properties to exclude whole jar content from the class scanner.

Fixes: #19112
tltv added a commit to vaadin/docs that referenced this issue May 20, 2024
mcollovati pushed a commit that referenced this issue May 27, 2024
Optimize class scanning of VaadinServletContextInitializer by excluding some commonly used jars and add support for vaadin.blocked-jar boolean property in META-INF/VAADIN/package.properties to exclude whole jar content from the class scanner.

Fixes: #19112
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 24.5.0.alpha1 and is also targeting the upcoming stable 24.5.0 version.

jouni added a commit to vaadin/docs that referenced this issue Jun 19, 2024
* docs: document JAR package filtering

RelatedTo: vaadin/flow#19117, vaadin/flow#19112

* Update configuration.adoc

* First pass at editing only added and changed text.

* Second pass at editing all text in touched file.

---------

Co-authored-by: Jouni Koivuviita <jouni@vaadin.com>
Co-authored-by: Russell J.T. Dyer <6652767+russelljtdyer@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: September 2024 (24.5)
Development

Successfully merging a pull request may close this issue.

2 participants