cqframework / clinical_quality_language

Clinical Quality Language (CQL) is an HL7 specification for the expression of clinical knowledge that can be used within both the Clinical Decision Support (CDS) and Clinical Quality Measurement (CQM) domains. This repository contains complementary tooling in support of that specification.
https://confluence.hl7.org/display/CDS/Clinical+Quality+Language
Apache License 2.0
257 stars 120 forks source link

Map ELM to Evaluator ELM without export/import into JSON/XML #868

Closed vitorpamplona closed 10 months ago

vitorpamplona commented 2 years ago

Currently, the engine uses a JSON mapper to compile CQL into evaluation-ready elm classes. All tests run a similar line to this:

CqlTranslator translator = CqlTranslator.fromFile(cqlFile, .... );
JsonCqlLibraryReader.read(translator.toJxson());

We have to find a way to directly compile CQL into evaluation classes to improve performance and memory use.

vitorpamplona commented 2 years ago

Some interesting early results on the performance of specific methods in the stack:

Compile:

CqlTranslator translator = CqlTranslator.fromText(cqlText, modelManager, new LibraryManager(modelManager), ucumService, opts);

Map (uses the CQL-Evaluator's Mapper):

Library l1 = LibraryMapper.INSTANCE.map(translator.toELM());

Parsing:

Library l2 = JsonCqlLibraryReader.read(new StringReader(translator.toJxson()));

Delta time and delta memory (before GC) of repeating 10 times the same compilation + mapping | parsing. Desktop runs

    Compile          Mapping         Parsing    Lib
  ΔTime ΔMemory   ΔTime ΔMemory  ΔTime  ΔMemory Lib
 3025ms  +173mb   242ms   +20mb  1340ms   +82mb CqlIntervalOperatorsTest.cql
  505ms   +96mb    15ms    +0mb   331ms   +45mb CqlIntervalOperatorsTest.cql
  438ms   +96mb    12ms    +0mb   311ms   +42mb CqlIntervalOperatorsTest.cql
  388ms   +96mb     7ms    +0mb   242ms   +43mb CqlIntervalOperatorsTest.cql
  349ms   +96mb     6ms    +0mb   225ms   +42mb CqlIntervalOperatorsTest.cql
  359ms   +92mb     8ms    +4mb   277ms   +41mb CqlIntervalOperatorsTest.cql
  426ms   +92mb     8ms    +0mb   200ms   +41mb CqlIntervalOperatorsTest.cql
  283ms   +96mb     5ms    +0mb   246ms   +43mb CqlIntervalOperatorsTest.cql
  319ms   +92mb     5ms    +0mb   185ms   +45mb CqlIntervalOperatorsTest.cql
  207ms   +92mb    13ms    +0mb   172ms   +43mb CqlIntervalOperatorsTest.cql

I have no idea why compiling the same file gets faster every time you do it :)

Compiling something larger puts us well beyond the 1GB/compile.

     Compile         Mapping         Parsing    Lib
  ΔTime ΔMemory   ΔTime ΔMemory  ΔTime  ΔMemory Lib
 9976ms +1394mb   642ms   +29mb  3655ms  +357mb CqlTestSuite.cql
 4550ms +1272mb    70ms    +8mb  1781ms  +297mb CqlTestSuite.cql
 3552ms +1264mb    65ms    +8mb  1496ms  +298mb CqlTestSuite.cql
 3861ms +1264mb    59ms    +8mb  1323ms  +296mb CqlTestSuite.cql
 3921ms +1260mb   103ms    +8mb  1263ms  +296mb CqlTestSuite.cql
 3727ms +1265mb    52ms    +8mb  1339ms  +294mb CqlTestSuite.cql
JPercival commented 10 months ago

No longer needed, engine and compiler share ELM graph