@@ -70,6 +70,7 @@ export type DataSchemaCompilerOptions = {
7070 compileContext ?: any ;
7171 allowNodeRequire ?: boolean ;
7272 compiledScriptCache : LRUCache < string , vm . Script > ;
73+ compiledJinjaCache : LRUCache < string , string > ;
7374} ;
7475
7576export type TranspileOptions = {
@@ -145,6 +146,8 @@ export class DataSchemaCompiler {
145146
146147 private readonly compiledScriptCache : LRUCache < string , vm . Script > ;
147148
149+ private readonly compiledJinjaCache : LRUCache < string , string > ;
150+
148151 private compileV8ContextCache : vm . Context | null = null ;
149152
150153 // FIXME: Is public only because of tests, should be private
@@ -178,6 +181,7 @@ export class DataSchemaCompiler {
178181 this . workerPool = null ;
179182 this . compilerId = options . compilerId || 'default' ;
180183 this . compiledScriptCache = options . compiledScriptCache ;
184+ this . compiledJinjaCache = options . compiledJinjaCache ;
181185 }
182186
183187 public compileObjects ( compileServices : CompilerInterface [ ] , objects , errorsReport : ErrorReporter ) {
@@ -684,17 +688,28 @@ export class DataSchemaCompiler {
684688 errorsReport : ErrorReporter ,
685689 options : TranspileOptions
686690 ) : Promise < ( FileContent | undefined ) > {
687- const renderedFile = await this . yamlCompiler . renderTemplate (
688- file ,
689- this . standalone ? { } : this . cloneCompileContextWithGetterAlias ( this . compileContext ) ,
690- this . pythonContext !
691- ) ;
691+ const cacheKey = crypto . createHash ( 'md5' ) . update ( JSON . stringify ( file . content ) ) . digest ( 'hex' ) ;
692+
693+ let renderedFileContent : string ;
694+
695+ if ( this . compiledJinjaCache . has ( cacheKey ) ) {
696+ renderedFileContent = this . compiledJinjaCache . get ( cacheKey ) ! ;
697+ } else {
698+ const renderedFile = await this . yamlCompiler . renderTemplate (
699+ file ,
700+ this . standalone ? { } : this . cloneCompileContextWithGetterAlias ( this . compileContext ) ,
701+ this . pythonContext !
702+ ) ;
703+ renderedFileContent = renderedFile . content ;
704+
705+ this . compiledJinjaCache . set ( cacheKey , renderedFileContent ) ;
706+ }
692707
693708 // We update the jinja/yaml file content to the rendered content
694709 // to reuse the same transpileYamlFile() flow afterward which
695710 // will update the content to the transpiled js content
696711 // avoiding costly YAML/Python parsing again.
697- file . content = renderedFile . content ;
712+ file . content = renderedFileContent ;
698713
699714 return this . transpileYamlFile ( file , errorsReport , options ) ;
700715 }
0 commit comments