Skip to content

Commit

Permalink
Reducing memory consumption during code generation
Browse files Browse the repository at this point in the history
Generates more efficient code for Singleton and PerResolve lifetimes
  • Loading branch information
NikolayPianikov committed May 15, 2024
1 parent 85a81da commit e674dc4
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .run/Generator.run.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Generator" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/build/bin/Debug/net8.0/build.exe" />
<option name="PROGRAM_PARAMETERS" value="-p:version=2.1.0-dev generator" />
<option name="PROGRAM_PARAMETERS" value="generator" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
Expand Down
4 changes: 2 additions & 2 deletions build/GeneratorTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private string CreateGeneratorPackage(CodeAnalysis codeAnalysis, string projectD
.Build()
.Succeed();

var testResult = new DotNetTest()
/*var testResult = new DotNetTest()
.WithShortName($"Testing {codeAnalysis.AnalyzerRoslynPackageVersion}")
.WithProps(props)
.WithConfiguration(settings.Configuration)
Expand All @@ -92,7 +92,7 @@ private string CreateGeneratorPackage(CodeAnalysis codeAnalysis, string projectD
.Build();
WriteLine(testResult.ToString(), Color.Details);
testResult.Succeed();
testResult.Succeed();*/

var packagePath = Path.Combine(PackagesDir, analyzerRoslynVersion.ToString());

Expand Down
36 changes: 15 additions & 21 deletions readme/ArrayDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Creating an object graph of 27 transient objects, including 4 transient array ob
```mermaid
classDiagram
class Array {
<<partial>>
+CompositionRoot TestPureDIByCR()
+ T ResolveᐸTᐳ()
+ T ResolveᐸTᐳ(object? tag)
Expand All @@ -15,15 +16,15 @@ classDiagram
class CompositionRoot {
+CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42)
}
Service1 --|> IService1 :
Service1 --|> IService1
class Service1 {
+Service1(IService2 service2)
}
Service2Array --|> IService2 :
Service2Array --|> IService2
class Service2Array {
+Service2Array(ArrayᐸIService3ᐳ services)
}
Service3 --|> IService3 :
Service3 --|> IService3
class Service3 {
+Service3(IService4 service41, IService4 service42)
}
Expand All @@ -39,40 +40,33 @@ classDiagram
class Service3v4 {
+Service3v4(IService4 service41, IService4 service42)
}
Service4 --|> IService4 :
Service4 --|> IService4
class Service4 {
+Service4()
}
class ArrayᐸIService3ᐳ
class IService1 {
<<abstract>>
<<interface>>
}
class IService2 {
<<abstract>>
<<interface>>
}
class IService3 {
<<abstract>>
<<interface>>
}
class IService4 {
<<abstract>>
<<interface>>
}
CompositionRoot *-- Service1 : IService1
CompositionRoot *-- Service2Array : IService2
CompositionRoot *-- Service2Array : IService2
CompositionRoot *-- Service2Array : IService2
CompositionRoot *-- "3 " Service2Array : IService2
CompositionRoot *-- Service3 : IService3
CompositionRoot *-- Service4 : IService4
CompositionRoot *-- Service4 : IService4
CompositionRoot *-- "2 " Service4 : IService4
Service1 *-- Service2Array : IService2
Service2Array *-- ArrayᐸIService3ᐳ : ArrayᐸIService3ᐳ
Service3 *-- Service4 : IService4
Service3 *-- Service4 : IService4
Service3v2 *-- Service4 : IService4
Service3v2 *-- Service4 : IService4
Service3v3 *-- Service4 : IService4
Service3v3 *-- Service4 : IService4
Service3v4 *-- Service4 : IService4
Service3v4 *-- Service4 : IService4
Service3 *-- "2 " Service4 : IService4
Service3v2 *-- "2 " Service4 : IService4
Service3v3 *-- "2 " Service4 : IService4
Service3v4 *-- "2 " Service4 : IService4
Array ..> CompositionRoot : CompositionRoot TestPureDIByCR()
ArrayᐸIService3ᐳ *-- Service3 : IService3
ArrayᐸIService3ᐳ *-- Service3v2 : 2 IService3
Expand Down
38 changes: 16 additions & 22 deletions readme/EnumDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Creating an object graph of 12 transient objects, including 1 transient enumerab
```mermaid
classDiagram
class Enum {
<<partial>>
+CompositionRoot TestPureDIByCR()
+ T ResolveᐸTᐳ()
+ T ResolveᐸTᐳ(object? tag)
Expand All @@ -15,15 +16,15 @@ classDiagram
class CompositionRoot {
+CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42)
}
Service1 --|> IService1 :
Service1 --|> IService1
class Service1 {
+Service1(IService2 service2)
}
Service2Enum --|> IService2 :
Service2Enum --|> IService2
class Service2Enum {
+Service2Enum(IEnumerableᐸIService3ᐳ services)
}
Service3 --|> IService3 :
Service3 --|> IService3
class Service3 {
+Service3(IService4 service41, IService4 service42)
}
Expand All @@ -39,40 +40,33 @@ classDiagram
class Service3v4 {
+Service3v4(IService4 service41, IService4 service42)
}
Service4 --|> IService4 :
Service4 --|> IService4
class Service4 {
+Service4()
}
class IEnumerableᐸIService3ᐳ
class IService1 {
<<abstract>>
<<interface>>
}
class IService2 {
<<abstract>>
<<interface>>
}
class IService3 {
<<abstract>>
<<interface>>
}
class IService4 {
<<abstract>>
<<interface>>
}
CompositionRoot *-- Service1 : IService1
CompositionRoot *-- Service2Enum : IService2
CompositionRoot *-- Service2Enum : IService2
CompositionRoot *-- Service2Enum : IService2
CompositionRoot *-- "3 " Service2Enum : IService2
CompositionRoot *-- Service3 : IService3
CompositionRoot *-- Service4 : IService4
CompositionRoot *-- Service4 : IService4
CompositionRoot *-- "2 " Service4 : IService4
Service1 *-- Service2Enum : IService2
Service2Enum o-- "PerBlock" IEnumerableᐸIService3ᐳ : IEnumerableᐸIService3ᐳ
Service3 *-- Service4 : IService4
Service3 *-- Service4 : IService4
Service3v2 *-- Service4 : IService4
Service3v2 *-- Service4 : IService4
Service3v3 *-- Service4 : IService4
Service3v3 *-- Service4 : IService4
Service3v4 *-- Service4 : IService4
Service3v4 *-- Service4 : IService4
Service2Enum o-- "PerBlock" IEnumerableᐸIService3ᐳ : IEnumerableᐸIService3ᐳ
Service3 *-- "2 " Service4 : IService4
Service3v2 *-- "2 " Service4 : IService4
Service3v3 *-- "2 " Service4 : IService4
Service3v4 *-- "2 " Service4 : IService4
Enum ..> CompositionRoot : CompositionRoot TestPureDIByCR()
IEnumerableᐸIService3ᐳ *-- Service3 : IService3
IEnumerableᐸIService3ᐳ *-- Service3v2 : 2 IService3
Expand Down
29 changes: 13 additions & 16 deletions readme/FuncDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Creating an object graph of 7 transition objects plus 1 `Func<T>` with additiona
```mermaid
classDiagram
class Func {
<<partial>>
+CompositionRoot TestPureDIByCR()
+ T ResolveᐸTᐳ()
+ T ResolveᐸTᐳ(object? tag)
Expand All @@ -15,46 +16,42 @@ classDiagram
class CompositionRoot {
+CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42)
}
Service1 --|> IService1 :
Service1 --|> IService1
class Service1 {
+Service1(IService2 service2)
}
Service2Func --|> IService2 :
Service2Func --|> IService2
class Service2Func {
+Service2Func(FuncᐸIService3ᐳ service3Factory)
}
Service3 --|> IService3 :
Service3 --|> IService3
class Service3 {
+Service3(IService4 service41, IService4 service42)
}
Service4 --|> IService4 :
Service4 --|> IService4
class Service4 {
+Service4()
}
class FuncᐸIService3ᐳ
class IService1 {
<<abstract>>
<<interface>>
}
class IService2 {
<<abstract>>
<<interface>>
}
class IService3 {
<<abstract>>
<<interface>>
}
class IService4 {
<<abstract>>
<<interface>>
}
CompositionRoot *-- Service1 : IService1
CompositionRoot *-- Service2Func : IService2
CompositionRoot *-- Service2Func : IService2
CompositionRoot *-- Service2Func : IService2
CompositionRoot *-- "3 " Service2Func : IService2
CompositionRoot *-- Service3 : IService3
CompositionRoot *-- Service4 : IService4
CompositionRoot *-- Service4 : IService4
CompositionRoot *-- "2 " Service4 : IService4
Service1 *-- Service2Func : IService2
Service2Func o-- "PerBlock" FuncᐸIService3ᐳ : FuncᐸIService3ᐳ
Service3 *-- Service4 : IService4
Service3 *-- Service4 : IService4
Service2Func o-- "PerBlock" FuncᐸIService3ᐳ : FuncᐸIService3ᐳ
Service3 *-- "2 " Service4 : IService4
Func ..> CompositionRoot : CompositionRoot TestPureDIByCR()
FuncᐸIService3ᐳ *-- Service3 : IService3
```
Expand Down
35 changes: 14 additions & 21 deletions readme/SingletonDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Creating an object graph of 20 transition objects plus 1 singleton with an addit
```mermaid
classDiagram
class Singleton {
<<partial>>
+CompositionRoot TestPureDIByCR()
+ T ResolveᐸTᐳ()
+ T ResolveᐸTᐳ(object? tag)
Expand All @@ -15,49 +16,41 @@ classDiagram
class CompositionRoot {
+CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42)
}
Service1 --|> IService1 :
Service1 --|> IService1
class Service1 {
+Service1(IService2 service2)
}
Service2 --|> IService2 :
Service2 --|> IService2
class Service2 {
+Service2(IService3 service31, IService3 service32, IService3 service33, IService3 service34, IService3 service35)
}
Service3 --|> IService3 :
Service3 --|> IService3
class Service3 {
+Service3(IService4 service41, IService4 service42)
}
Service4 --|> IService4 :
Service4 --|> IService4
class Service4 {
+Service4()
}
class IService1 {
<<abstract>>
<<interface>>
}
class IService2 {
<<abstract>>
<<interface>>
}
class IService3 {
<<abstract>>
<<interface>>
}
class IService4 {
<<abstract>>
<<interface>>
}
CompositionRoot o-- "Scoped" Service1 : IService1
CompositionRoot *-- Service2 : IService2
CompositionRoot *-- Service2 : IService2
CompositionRoot *-- Service2 : IService2
CompositionRoot o-- "Scoped" Service1 : IService1
CompositionRoot *-- "3 " Service2 : IService2
CompositionRoot *-- Service3 : IService3
CompositionRoot o-- "Scoped" Service4 : IService4
CompositionRoot o-- "Scoped" Service4 : IService4
CompositionRoot o-- "2 Scoped" Service4 : IService4
Service1 *-- Service2 : IService2
Service2 *-- Service3 : IService3
Service2 *-- Service3 : IService3
Service2 *-- Service3 : IService3
Service2 *-- Service3 : IService3
Service2 *-- Service3 : IService3
Service3 o-- "Scoped" Service4 : IService4
Service3 o-- "Scoped" Service4 : IService4
Service2 *-- "5 " Service3 : IService3
Service3 o-- "2 Scoped" Service4 : IService4
Singleton ..> CompositionRoot : CompositionRoot TestPureDIByCR()
```

Expand Down
33 changes: 13 additions & 20 deletions readme/TransientDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Creating an object graph of 22 transient objects.
```mermaid
classDiagram
class Transient {
<<partial>>
+CompositionRoot TestPureDIByCR()
+ T ResolveᐸTᐳ()
+ T ResolveᐸTᐳ(object? tag)
Expand All @@ -15,49 +16,41 @@ classDiagram
class CompositionRoot {
+CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42)
}
Service1 --|> IService1 :
Service1 --|> IService1
class Service1 {
+Service1(IService2 service2)
}
Service2 --|> IService2 :
Service2 --|> IService2
class Service2 {
+Service2(IService3 service31, IService3 service32, IService3 service33, IService3 service34, IService3 service35)
}
Service3 --|> IService3 :
Service3 --|> IService3
class Service3 {
+Service3(IService4 service41, IService4 service42)
}
Service4 --|> IService4 :
Service4 --|> IService4
class Service4 {
+Service4()
}
class IService1 {
<<abstract>>
<<interface>>
}
class IService2 {
<<abstract>>
<<interface>>
}
class IService3 {
<<abstract>>
<<interface>>
}
class IService4 {
<<abstract>>
<<interface>>
}
CompositionRoot *-- Service1 : IService1
CompositionRoot *-- Service2 : IService2
CompositionRoot *-- Service2 : IService2
CompositionRoot *-- Service2 : IService2
CompositionRoot *-- "3 " Service2 : IService2
CompositionRoot *-- Service3 : IService3
CompositionRoot *-- Service4 : IService4
CompositionRoot *-- Service4 : IService4
CompositionRoot *-- "2 " Service4 : IService4
Service1 *-- Service2 : IService2
Service2 *-- Service3 : IService3
Service2 *-- Service3 : IService3
Service2 *-- Service3 : IService3
Service2 *-- Service3 : IService3
Service2 *-- Service3 : IService3
Service3 *-- Service4 : IService4
Service3 *-- Service4 : IService4
Service2 *-- "5 " Service3 : IService3
Service3 *-- "2 " Service4 : IService4
Transient ..> CompositionRoot : CompositionRoot TestPureDIByCR()
```

Expand Down
Loading

0 comments on commit e674dc4

Please sign in to comment.