flow icon indicating copy to clipboard operation
flow copied to clipboard

Speedup startup and reload time of 24.4

Open tltv opened this issue 4 months ago • 0 comments

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 https://github.com/vaadin/flow/issues/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

https://github.com/vaadin/flow/issues/18812

tltv avatar Apr 05 '24 08:04 tltv