Macro. Parse merged code only if there are optimization edits.

This saves another 120 ms.

Bug: https://github.com/dart-lang/sdk/issues/55784
Change-Id: I4b195f977b7e49cc5b07dcecd4836b3f25399428
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372820
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Konstantin Shcheglov 2024-06-22 16:30:11 +00:00 committed by Commit Queue
parent 1d38fc4bf2
commit 755d4e0531

View file

@ -533,18 +533,6 @@ class LibraryBuilder with MacroApplicationsContainer {
return;
}
var mergedUnit = performance.run(
'mergedUnit',
(performance) {
performance.getDataInt('length').add(augmentationCode.length);
return kind.file.parseCode(
code: augmentationCode,
errorListener: AnalysisErrorListener.NULL_LISTENER,
performance: performance,
);
},
);
kind.disposeMacroAugmentations(disposeFiles: true);
// Remove import for partial macro augmentations.
@ -636,12 +624,26 @@ class LibraryBuilder with MacroApplicationsContainer {
unitElement: unitElement,
augmentation: augmentation,
).perform(updateConstants: () {
MacroUpdateConstantsForOptimizedCode(
libraryElement: element,
unitNode: mergedUnit,
codeEdits: optimizedCodeEdits,
unitElement: unitElement,
).perform();
if (optimizedCodeEdits.isNotEmpty) {
var mergedUnit = performance.run(
'mergedUnit',
(performance) {
performance.getDataInt('length').add(augmentationCode.length);
return kind.file.parseCode(
code: augmentationCode,
errorListener: AnalysisErrorListener.NULL_LISTENER,
performance: performance,
);
},
);
MacroUpdateConstantsForOptimizedCode(
libraryElement: element,
unitNode: mergedUnit,
codeEdits: optimizedCodeEdits,
unitElement: unitElement,
).perform();
}
});
// Set offsets the same way as when reading from summary.