From f345cb2e80b10cb93b15ecd3ac2eb544ac4ca8bb Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 12 Jun 2023 16:21:53 -0400 Subject: [PATCH 1/2] Adds a compiled Library cache that survives multiple executions of the evaluator. --- .../com/google/android/fhir/workflow/FhirOperator.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt b/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt index 9dd1624af7..2033c55a7c 100644 --- a/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt +++ b/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt @@ -136,11 +136,20 @@ internal constructor( ) private val endpointConverter = EndpointConverter(adapterFactory) + // Keeps a cached copy of all **compiled** libraries. + // TODO: Migrate upstream's CQL Evaluator to a hashmap interface and then use an LruCache here. + val compiledLibraryCache = + HashMap< + org.cqframework.cql.elm.execution.VersionedIdentifier, + org.cqframework.cql.elm.execution.Library + >() + private val evaluatorBuilderSupplier = Supplier { CqlEvaluatorBuilder() .withLibrarySourceProvider(libraryContentProvider) .withCqlOptions(CqlOptions.defaultOptions()) .withTerminologyProvider(fhirEngineTerminologyProvider) + .withLibraryCache(compiledLibraryCache) } private val libraryProcessor = From 8aaba3343589eb73e870d6a6977e2029011aefe8 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 19 Jun 2023 11:24:26 -0400 Subject: [PATCH 2/2] Clarifies the TODO --- .../java/com/google/android/fhir/workflow/FhirOperator.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt b/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt index 2033c55a7c..57c708e39c 100644 --- a/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt +++ b/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt @@ -137,7 +137,9 @@ internal constructor( private val endpointConverter = EndpointConverter(adapterFactory) // Keeps a cached copy of all **compiled** libraries. - // TODO: Migrate upstream's CQL Evaluator to a hashmap interface and then use an LruCache here. + // TODO: Migrate the upstream's CqlEvaluatorBuilder.withLibraryCache code, where this variable + // is used, to an interface and then this HashMap to a lifecycle-aware caching data structure + // (e.g. LruCache). val compiledLibraryCache = HashMap< org.cqframework.cql.elm.execution.VersionedIdentifier,