-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rosetta):
transliterate
tries to recompile samples from tablets (…
…#3324) In #3262, the performance of `transliterate` was improved by running an `extract` before translating, because `extract` has the facilities to do parallel translate, and can read from a cache. However, another thing `extract` does is *discard translations from the cache* if they are considered "dirty" for some reason. This reason can be: the current source is different than the cached source, the translation mechanism has changed, compilation didn't succeed last time, or the types referenced in the example have changed. This is actually not desirable for `transliterate`, which wants to do a last-ditch effort to translate whatever is necessary to translate, but should really take what it can from the cache if there's a cached translation available. Add a flag to allow reading dirty translations from the cache. Also adds the `rosetta coverage` command, which I used to find out why the Construct Hub performance on the newest `aws-cdk-lib` version is still poor. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
- Loading branch information
Showing
6 changed files
with
219 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { loadAssemblies, allTypeScriptSnippets, loadAllDefaultTablets } from '../jsii/assemblies'; | ||
import * as logging from '../logging'; | ||
import { RosettaTranslator } from '../rosetta-translator'; | ||
import { formatLocation } from '../snippet'; | ||
|
||
export async function checkCoverage(assemblyLocations: readonly string[]): Promise<void> { | ||
logging.info(`Loading ${assemblyLocations.length} assemblies`); | ||
const assemblies = await loadAssemblies(assemblyLocations, false); | ||
|
||
const snippets = Array.from(allTypeScriptSnippets(assemblies, true)); | ||
|
||
const translator = new RosettaTranslator({ | ||
assemblies: assemblies.map((a) => a.assembly), | ||
allowDirtyTranslations: true, | ||
}); | ||
translator.addTabletsToCache(...Object.values(await loadAllDefaultTablets(assemblies))); | ||
|
||
process.stdout.write(`- ${snippets.length} total snippets.\n`); | ||
process.stdout.write(`- ${translator.cache.count} translations in cache.\n`); | ||
process.stdout.write('\n'); | ||
|
||
const results = translator.readFromCache(snippets, true, true); | ||
process.stdout.write(`- ${results.translations.length - results.dirtyCount} successful cache hits.\n`); | ||
process.stdout.write(` ${results.infusedCount} infused.\n`); | ||
process.stdout.write(`- ${results.dirtyCount} translations in cache but dirty (ok for pacmak, transliterate)\n`); | ||
process.stdout.write(` ${results.dirtySourceCount} sources have changed.\n`); | ||
process.stdout.write(` ${results.dirtyTranslatorCount} translator has changed.\n`); | ||
process.stdout.write(` ${results.dirtyTypesCount} types have changed.\n`); | ||
process.stdout.write(` ${results.dirtyDidntCompile} did not successfully compile.\n`); | ||
process.stdout.write(`- ${results.remaining.length} snippets untranslated.\n`); | ||
|
||
for (const remaining of results.remaining) { | ||
process.stdout.write(` ${formatLocation(remaining.location)}\n`); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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