Excessive DMN file size due to added empty lines and memory issues during DMN evaluation with PostgreSQL

Hello Camunda Community,

I’m experiencing two interconnected issues with my Camunda setup, both involving the handling of DMN evaluations. I’m dynamically generating DMN models using the Camunda DMN model API and deploying them using Camunda’s repository service. My setup uses PostgreSQL as the database.

The first issue arises during the generation and writing of DMN files using the Dmn.writeModelToFile() function. This operation introduces a large number of empty lines into the DMN XML, leading to inflated file sizes — up to 2,000,000 lines and 20 MB per file, with non-empty (useful) lines around 1000.

Here’s a snippet of my code:

File file = new File("userBasedThreshold.dmn");
Dmn.writeModelToFile(file, modelInstance);
Deployment deploy = repositoryService
                .addInputStream(file.getName(), Files.newInputStream(file.toPath()))

The second issue surfaces when a BPMN process requires a DMN evaluation. Although I’ve set the decision table’s binding to ‘latest’, Camunda seems to attempt to load all deployed versions of the DMN into memory. This behavior triggers a “Ran out of memory retrieving query results” error from PostgreSQL:

Error querying database.  
Cause: org.postgresql.util.PSQLException: Ran out of memory retrieving query results. 
The error may exist in org/camunda/bpm/engine/impl/mapping/entity/Resource.xml 
The error may involve org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity.selectResourceByDeploymentIdAndResourceName_postgres-Inline 
The error occurred while setting parameters 
SQL: select * from ACT_GE_BYTEARRAY where DEPLOYMENT_ID_ = ? AND NAME_ = ? 
Cause: org.postgresql.util.PSQLException: Ran out of memory retrieving query results.

This error specifically appears when querying the ACT_GE_BYTEARRAY table.

To tackle these issues, I am seeking advice on:

  1. What might be causing the addition of excessive empty lines when writing DMN files using the Dmn.writeModelToFile() function? Could this be related to the settings of Camunda’s XML transformer?
  2. How can I limit the versions of DMN loaded into memory during runtime given that I’ve used ‘latest’ as the binding mode?

Any insights or advice would be greatly appreciated.

I really appreciate any help you can provide.