-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(rosetta): reuse translation results from a cache #3101
Conversation
28d29fc
to
5399c71
Compare
…long with translations, we can reuse existing translations if we know nothing changed. A snippet needs to be recompiled if: - Its source text changes: hash will be different - Its fixture changes: fullSource will be different - The referenced types have changed: fingerprint will be different
…iagnostic down more in favor of RosettaDiagnostic
23747dc
to
6df1bfe
Compare
6df1bfe
to
2901b56
Compare
The title of this Pull Request does not conform with [Conventional Commits] guidelines. It will need to be adjusted before the PR can be merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, my eyes did glaze over a bit here at one point, but I think I was paying attention for all the salient points.
🤞
} | ||
|
||
/** | ||
* Translate all snippets | ||
* | ||
* We are now always using workers, as we are targeting Node 12+. | ||
*/ | ||
async function translateAll( | ||
snippets: IterableIterator<TypeScriptSnippet>, | ||
export async function translateAll( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just exported for testing? Might be worth a comment if so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was originally, no longer needs to be. Good catch.
* Bump this when you change something in the implementation to invalidate | ||
* existing cached translations. | ||
*/ | ||
public static readonly VERSION = '1'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Food for (future) thought -- this feels very much like a good intentions thing. Could we mechanize this a bit better somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe. Not sure!
public get didCompile() { | ||
return this._didCompile; | ||
} | ||
public readonly snippet: TranslatedSnippetSchema; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~
The naming here is a bit odd. TranslatedSnippet.snippet
, which returns a TranslatedSnippetSchema
, which reads to me like the snippet itself. It leads to a lot of snippet.snippet
in the code, which is never great...
It's almost like TranslatedSnippet
should implement TranslatedSnippetSchema
. Am I off there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the names would be better to say TranslatedSnippetOperations
and TranslatedSnippet
. The class represents the operations on the pure-data object.
But I do need the ability to get the pure-data object out in a lightweight way.
Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it! |
Merging (with squash)... |
Merging (with squash)... |
Merging (with squash)... |
By fingerprinting types in an assembly and storing the fingerprints along with translations, we can reuse existing translations if we know nothing changed.
A snippet needs to be recompiled if:
Since we have many duplicate snippets (especially
cluster.enableSingleUserRotation()
crops up a lot 🙂), I've had to encode the source location for the snippet into the key. Since that means that location encoding is now significant and needs to be correct, some refactoring around encoding snippet locations has become important.Incidentally, this will also fix broken translations originating from
monocdk
from overwriting perfectly cromulent translations in the@aws-cdk
packages.Refactorings in this PR:
{ api: 'member', fqn: '@ns/package.type', memberName: 'bucketName' }
(anApiLocation
), and have been added to many, many places, includingjsii-pacmak
.VERSION
, which is used to invalidate cached translations if we change something about the implementation of the translator.TranslatedSnippet
had a copy of all the data in aTranslatedSnippetSchema
, and was copying back and forth. Change it to just hold on to aTranslatedSnippet
internally. It now represents the operations that can be done to aTranslatedSnippetSchema
.ts.Diagnostic
toRosettaDiagnostic
is now done even earlier (closer to the code that deals with the TS compiler).IterableIterator
, but just an plain old array.readonly
fields on a number of structs.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.