@@ -70,6 +70,7 @@ export type DataSchemaCompilerOptions = {
7070 compileContext ?: any ;
7171 allowNodeRequire ?: boolean ;
7272 compiledScriptCache : LRUCache < string , vm . Script > ;
73+ compiledYamlCache : 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 compiledYamlCache : 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 . compiledYamlCache = options . compiledYamlCache ;
181185 }
182186
183187 public compileObjects ( compileServices : CompilerInterface [ ] , objects , errorsReport : ErrorReporter ) {
@@ -631,6 +635,15 @@ export class DataSchemaCompiler {
631635 errorsReport : ErrorReporter ,
632636 { cubeNames, cubeSymbols, contextSymbols, transpilerNames, compilerId, stage } : TranspileOptions
633637 ) : Promise < ( FileContent | undefined ) > {
638+ const cacheKey = crypto . createHash ( 'md5' ) . update ( JSON . stringify ( file . content ) ) . digest ( 'hex' ) ;
639+
640+ if ( this . compiledYamlCache . has ( cacheKey ) ) {
641+ file . content = this . compiledYamlCache . get ( cacheKey ) ! ;
642+ file . convertedToJs = true ;
643+
644+ return { ...file } ;
645+ }
646+
634647 /* if (getEnv('transpilationNative')) {
635648
636649 } else */ if ( getEnv ( 'transpilationWorkerThreads' ) ) {
@@ -649,6 +662,8 @@ export class DataSchemaCompiler {
649662 file . content = res . content ;
650663 file . convertedToJs = true ;
651664
665+ this . compiledYamlCache . set ( cacheKey , res . content ) ;
666+
652667 return { ...file , content : res . content } ;
653668 } else {
654669 const transpiledFile = this . yamlCompiler . transpileYamlFile ( file , errorsReport ) ;
@@ -661,6 +676,8 @@ export class DataSchemaCompiler {
661676 file . convertedToJs = true ;
662677 }
663678
679+ this . compiledYamlCache . set ( cacheKey , transpiledFile ?. content || '' ) ;
680+
664681 return transpiledFile ;
665682 }
666683 }
0 commit comments