Fix slow Lombok initialization caused by ShadowClassLoader scanning entire classpath#7205
Merged
Conversation
…ntire classpath Lombok's ShadowClassLoader.getResources() calls isPartOfShadowSuffix() on every jar URL from the parent classloader, opening each as a ZipInputStream and reading every entry to check for lombok-prefixed paths. On large classpaths (e.g. Moderne CLI), this burns hundreds of seconds of CPU. Wrap the parent classloader with a ResourceFilteredClassLoader that returns empty results for resource enumeration while still delegating class loading normally. This forces the ShadowClassLoader to rely solely on its override jars (set via shadow.override.lombok), which already contain everything Lombok needs (lombok.jar + rewrite-java-lombok).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
When parsing projects that use Lombok on large classpaths (e.g. Moderne CLI), Lombok's
ShadowClassLoaderspends hundreds of seconds of CPU duringLombokProcessor.init(). TheShadowClassLoader.getResources()method callsisPartOfShadowSuffix()on every jar URL from the parent classloader, which opens each jar as aZipInputStreamand sequentially reads every entry to check for lombok-prefixed paths. On a classpath with many large jars, this is extremely slow.Stack trace from a
jstacksample showing the bottleneck (328s CPU / 384s elapsed):Summary
ShadowClassLoaderwith aResourceFilteredClassLoaderthat returns empty results forgetResources()/getResource(), while still delegating class loading normallyShadowClassLoaderto rely solely on its override jars (set viashadow.override.lombok), which already contain everything Lombok needs (lombok.jar+rewrite-java-lombok)LombokSupport.java— no parser modifications neededTest plan
rewrite-java-lombokmodule tests passrewrite-java-25Lombok-specific tests passjstackthat theShadowClassLoaderscanning bottleneck is eliminated — Lombok now proceeds directly to annotation processing