You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OpenEJBContextConfig.isIncluded() resolves the canonical path of the module
roots and of the web resource on every call, and Tomcat calls processAnnotationsWebResource() once per web resource. On a WAR with a few
hundred classes under WEB-INF/classes that is thousands of filesystem
syscalls, most of them resolving the same handful of paths again and again.
Three changes, no behaviour change:
Memoise File.getCanonicalFile() and the URL to File conversion. Both
mappings are stable for the lifetime of a deploy and the config instance is
per context.
Return early from processAnnotationsWebResource() once every module has
been processed. There is nothing left to match the resource against, and that
branch never delegates to super, so resolving the resource is wasted work.
Reuse the path from FileResource.getCanonicalPath() instead of letting isIncluded() resolve the same, already canonical, path a second time.
Measured on a synthetic WAR (40 jars, 513 classes in WEB-INF/classes) with tomee-embedded: isIncluded() accounted for 165 of 468 deploy-phase profiler
samples before the change and 1 after, and deploy wall time dropped ~25%.
Note this was measured on Windows, where getCanonicalPath() is considerably
more expensive than on Linux, so expect a smaller gain there.
Nice speedup, logic checks out. Two changes I'd make before merge:
Use ConcurrentHashMap for both caches. With parallelAnnotationScanning="true", Tomcat runs processAnnotationsUrl on multiple utility-executor threads, which reaches the maps via internalProcessAnnotations → isIncludedIn. Concurrent puts into a plain HashMap can lose entries or corrupt the table.
Clear both maps in configureStop(), like webInfClassesAnnotationsProcessed. The listener survives context stop/start, so after a reload canonicalFiles can hold stale resolutions (symlinks/paths may have changed), and both maps otherwise retain ~one entry per class file for the life of the context.
Also: please file a TOMEE JIRA and reference it in the title/commit, per project convention.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Speed up annotation processing during WAR deploy
OpenEJBContextConfig.isIncluded()resolves the canonical path of the moduleroots and of the web resource on every call, and Tomcat calls
processAnnotationsWebResource()once per web resource. On a WAR with a fewhundred classes under
WEB-INF/classesthat is thousands of filesystemsyscalls, most of them resolving the same handful of paths again and again.
Three changes, no behaviour change:
File.getCanonicalFile()and the URL toFileconversion. Bothmappings are stable for the lifetime of a deploy and the config instance is
per context.
processAnnotationsWebResource()once every module hasbeen processed. There is nothing left to match the resource against, and that
branch never delegates to
super, so resolving the resource is wasted work.FileResource.getCanonicalPath()instead of lettingisIncluded()resolve the same, already canonical, path a second time.Measured on a synthetic WAR (40 jars, 513 classes in
WEB-INF/classes) withtomee-embedded:isIncluded()accounted for 165 of 468 deploy-phase profilersamples before the change and 1 after, and deploy wall time dropped ~25%.
Note this was measured on Windows, where
getCanonicalPath()is considerablymore expensive than on Linux, so expect a smaller gain there.
Also see apache/tomcat#1030