DevBoost / JaMoPP

JaMoPP can parse Java source and byte code into EMF-based models and vice versa. It preserves source formatting and can be used for code analysis and refactoring.
17 stars 18 forks source link

Reducing JavaDefaultNameProvider instances #13

Open BenjaminKlatt opened 10 years ago

BenjaminKlatt commented 10 years ago

Current Implementation

Each instance of JavaDefaultResolverDelegate indirectly instantiates a new JavaDefaultNameProvider as an instance of a IJavaNameProvider by calling JavaMetaInformation.createNameProvider(). While the delegate uses a single instance of JavaMetaInformation, a new instance of the JavaDefaultNameProvider is created in the createNameProvider() method.

With the ArgoUML based case study performed in the SPLevo / KoPL project, this leads to more then 400,000 not necessary instances of this class. (Note, the JProfiler screenshot provided below is made during the processing. The final result is not possible at the time of writing, because JaMoPP does not finish in a reasonable time yet.

jamopp-profiling-javadefaultnameprovider-instances

Code Review Results

IJavaNameProvider provides only the method getNames(), and JavaDefaultNameProvider's implementation is status-independend, threadsafe and does not require a fresh instance with for every JavaDefaultResolverDelegate, or even with each call to JavaMetaInformation.createNameProvider()

Recommended Refactoring

A lightweight refactoring to prevent the creation of all these unnecessary instances is to change the createNameProvider() method to always return the same JavaDefaultResolverDelegate instance with each create call.