@@ -22,7 +22,11 @@ Future<void> runBenchmarks(MacroExecutor executor, Uri macroUri) async {
22
22
'String' : stringIdentifier,
23
23
'Map' : mapIdentifier,
24
24
'Object' : objectIdentifier,
25
- }
25
+ },
26
+ jsonSerializableUri: {
27
+ 'FromJson' : fromJsonMacroIdentifier,
28
+ 'ToJson' : toJsonMacroIdentifier,
29
+ },
26
30
}, constructors: {}, enumValues: {}, fields: {
27
31
myClass: myClassFields
28
32
}, methods: {});
@@ -37,107 +41,129 @@ Future<void> runBenchmarks(MacroExecutor executor, Uri macroUri) async {
37
41
for (final field in fields) field.identifier: field,
38
42
};
39
43
final instantiateBenchmark =
40
- JsonSerializableInstantiateBenchmark (executor, macroUri);
44
+ InstantiateBenchmark (executor, macroUri, 'JsonSerializable' );
41
45
await instantiateBenchmark.report ();
42
46
final instanceId = instantiateBenchmark.instanceIdentifier;
43
- final typesBenchmark = JsonSerializableTypesPhaseBenchmark (
44
- executor, macroUri, instanceId, introspector);
45
- await typesBenchmark.report ();
46
- BuildAugmentationLibraryBenchmark .reportAndPrint (
47
- executor,
48
- [if (typesBenchmark.result != null ) typesBenchmark.result! ],
49
- identifierDeclarations);
50
47
final declarationsBenchmark = JsonSerializableDeclarationsPhaseBenchmark (
51
48
executor, macroUri, instanceId, introspector);
52
49
await declarationsBenchmark.report ();
53
50
BuildAugmentationLibraryBenchmark .reportAndPrint (
54
51
executor,
55
52
[if (declarationsBenchmark.result != null ) declarationsBenchmark.result! ],
56
53
identifierDeclarations);
54
+
57
55
introspector.constructors[myClass] = myClassConstructors;
58
- final definitionsBenchmark = JsonSerializableDefinitionPhaseBenchmark (
59
- executor, macroUri, instanceId, introspector);
60
- await definitionsBenchmark.report ();
56
+ introspector.methods[myClass] = myClassMethods;
57
+
58
+ final fromJsonInstantiateBenchmark =
59
+ InstantiateBenchmark (executor, macroUri, 'FromJson' );
60
+ await fromJsonInstantiateBenchmark.report ();
61
+ final fromJsonDefinitionsBenchmark = FromJsonDefinitionPhaseBenchmark (
62
+ executor,
63
+ macroUri,
64
+ fromJsonInstantiateBenchmark.instanceIdentifier,
65
+ introspector);
66
+ await fromJsonDefinitionsBenchmark.report ();
61
67
BuildAugmentationLibraryBenchmark .reportAndPrint (
62
68
executor,
63
- [if (definitionsBenchmark.result != null ) definitionsBenchmark.result! ],
69
+ [
70
+ if (fromJsonDefinitionsBenchmark.result != null )
71
+ fromJsonDefinitionsBenchmark.result!
72
+ ],
73
+ identifierDeclarations);
74
+
75
+ final toJsonInstantiateBenchmark =
76
+ InstantiateBenchmark (executor, macroUri, 'ToJson' );
77
+ await toJsonInstantiateBenchmark.report ();
78
+ final toJsonDefinitionsBenchmark = ToJsonDefinitionPhaseBenchmark (executor,
79
+ macroUri, toJsonInstantiateBenchmark.instanceIdentifier, introspector);
80
+ await toJsonDefinitionsBenchmark.report ();
81
+ BuildAugmentationLibraryBenchmark .reportAndPrint (
82
+ executor,
83
+ [
84
+ if (toJsonDefinitionsBenchmark.result != null )
85
+ toJsonDefinitionsBenchmark.result!
86
+ ],
64
87
identifierDeclarations);
65
88
}
66
89
67
- class JsonSerializableInstantiateBenchmark extends AsyncBenchmarkBase {
90
+ class InstantiateBenchmark extends AsyncBenchmarkBase {
68
91
final MacroExecutor executor;
69
92
final Uri macroUri;
70
93
late MacroInstanceIdentifier instanceIdentifier;
94
+ final String macroName;
71
95
72
- JsonSerializableInstantiateBenchmark (this .executor, this .macroUri)
73
- : super ('JsonSerializableInstantiate ' );
96
+ InstantiateBenchmark (this .executor, this .macroUri, this .macroName )
97
+ : super ('${ macroName }Instantiate ' );
74
98
75
99
Future <void > run () async {
76
100
instanceIdentifier = await executor.instantiateMacro (
77
- macroUri, 'JsonSerializable' , '' , Arguments ([], {}));
101
+ macroUri, macroName , '' , Arguments ([], {}));
78
102
}
79
103
}
80
104
81
- class JsonSerializableTypesPhaseBenchmark extends AsyncBenchmarkBase {
105
+ class JsonSerializableDeclarationsPhaseBenchmark extends AsyncBenchmarkBase {
82
106
final MacroExecutor executor;
83
107
final Uri macroUri;
84
108
final MacroInstanceIdentifier instanceIdentifier;
85
- final TypePhaseIntrospector introspector;
109
+ final DeclarationPhaseIntrospector introspector;
110
+
86
111
MacroExecutionResult ? result;
87
112
88
- JsonSerializableTypesPhaseBenchmark (
113
+ JsonSerializableDeclarationsPhaseBenchmark (
89
114
this .executor, this .macroUri, this .instanceIdentifier, this .introspector)
90
- : super ('JsonSerializableTypesPhase ' );
115
+ : super ('JsonSerializableDeclarationsPhase ' );
91
116
92
117
Future <void > run () async {
118
+ result = null ;
93
119
if (instanceIdentifier.shouldExecute (
94
- DeclarationKind .classType, Phase .types )) {
95
- result = await executor.executeTypesPhase (
120
+ DeclarationKind .classType, Phase .declarations )) {
121
+ result = await executor.executeDeclarationsPhase (
96
122
instanceIdentifier, myClass, introspector);
97
123
}
98
124
}
99
125
}
100
126
101
- class JsonSerializableDeclarationsPhaseBenchmark extends AsyncBenchmarkBase {
127
+ class FromJsonDefinitionPhaseBenchmark extends AsyncBenchmarkBase {
102
128
final MacroExecutor executor;
103
129
final Uri macroUri;
104
130
final MacroInstanceIdentifier instanceIdentifier;
105
- final DeclarationPhaseIntrospector introspector;
131
+ final DefinitionPhaseIntrospector introspector;
106
132
107
133
MacroExecutionResult ? result;
108
134
109
- JsonSerializableDeclarationsPhaseBenchmark (
135
+ FromJsonDefinitionPhaseBenchmark (
110
136
this .executor, this .macroUri, this .instanceIdentifier, this .introspector)
111
- : super ('JsonSerializableDeclarationsPhase ' );
137
+ : super ('FromJsonDefinitionPhase ' );
112
138
113
139
Future <void > run () async {
114
140
result = null ;
115
141
if (instanceIdentifier.shouldExecute (
116
- DeclarationKind .classType , Phase .declarations )) {
117
- result = await executor.executeDeclarationsPhase (
118
- instanceIdentifier, myClass , introspector);
142
+ DeclarationKind .constructor , Phase .definitions )) {
143
+ result = await executor.executeDefinitionsPhase (
144
+ instanceIdentifier, myClassConstructors.single , introspector);
119
145
}
120
146
}
121
147
}
122
148
123
- class JsonSerializableDefinitionPhaseBenchmark extends AsyncBenchmarkBase {
149
+ class ToJsonDefinitionPhaseBenchmark extends AsyncBenchmarkBase {
124
150
final MacroExecutor executor;
125
151
final Uri macroUri;
126
152
final MacroInstanceIdentifier instanceIdentifier;
127
153
final DefinitionPhaseIntrospector introspector;
128
154
129
155
MacroExecutionResult ? result;
130
156
131
- JsonSerializableDefinitionPhaseBenchmark (
157
+ ToJsonDefinitionPhaseBenchmark (
132
158
this .executor, this .macroUri, this .instanceIdentifier, this .introspector)
133
- : super ('JsonSerializableDefinitionPhase ' );
159
+ : super ('ToJsonDefinitionPhase ' );
134
160
135
161
Future <void > run () async {
136
162
result = null ;
137
163
if (instanceIdentifier.shouldExecute (
138
- DeclarationKind .classType , Phase .definitions)) {
164
+ DeclarationKind .method , Phase .definitions)) {
139
165
result = await executor.executeDefinitionsPhase (
140
- instanceIdentifier, myClass , introspector);
166
+ instanceIdentifier, myClassMethods.single , introspector);
141
167
}
142
168
}
143
169
}
@@ -222,3 +248,34 @@ final myClassConstructors = [
222
248
definingType: myClass.identifier,
223
249
isFactory: true ),
224
250
];
251
+
252
+ final myClassMethods = [
253
+ MethodDeclarationImpl (
254
+ id: RemoteInstance .uniqueId,
255
+ identifier: IdentifierImpl (id: RemoteInstance .uniqueId, name: 'toJson' ),
256
+ isGetter: false ,
257
+ isOperator: false ,
258
+ isSetter: false ,
259
+ isStatic: false ,
260
+ library: fooLibrary,
261
+ metadata: [],
262
+ hasBody: false ,
263
+ hasExternal: false ,
264
+ namedParameters: [],
265
+ positionalParameters: [],
266
+ returnType: NamedTypeAnnotationImpl (
267
+ id: RemoteInstance .uniqueId,
268
+ isNullable: false ,
269
+ identifier: mapIdentifier,
270
+ typeArguments: [stringType, dynamicType]),
271
+ typeParameters: [],
272
+ definingType: myClass.identifier),
273
+ ];
274
+
275
+ final jsonSerializableUri =
276
+ Uri .parse ('package:macro_proposal/json_serializable.dart' );
277
+
278
+ final fromJsonMacroIdentifier =
279
+ IdentifierImpl (id: RemoteInstance .uniqueId, name: 'FromJson' );
280
+ final toJsonMacroIdentifier =
281
+ IdentifierImpl (id: RemoteInstance .uniqueId, name: 'ToJson' );
0 commit comments