Aspose compression is consuming more RAM and CPU cores

Hi Team,
We recently implemented compression to reduce file sizes. However, we’ve observed a significant increase in resource consumption, which has led to API performance degradation. Could you please suggest possible solutions to address this issue?

Here is our approach.

   @GetMapping("/excel")
    public ResponseEntity<byte[]> generateExcel() throws Exception {
        Workbook workbook = new Workbook();
        Worksheet sheet = workbook.getWorksheets().get(0);
//        sheet.getCells().get("A1").putValue("Hello, Aspose Cells!");
        // Add data to the worksheet to increase the file size
        for (int row = 0; row < 1500; row++) {
            for (int col = 0; col < 10; col++) {
                sheet.getCells().get(row, col).putValue("Row " + row + " Col " + col);
            }
        }

        try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
            OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.XLSX);
            saveOptions.setCompressionType(9); // Maximum compression
            workbook.save(outputStream, saveOptions);

            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
            headers.setContentDisposition(ContentDisposition.attachment().filename("example.xlsx").build());

            return ResponseEntity.ok()
                    .headers(headers)
                    .body(outputStream.toByteArray());
        }
    }

@VaradS

• Is the high RAM and CPU usage occurring during the compression process itself, or during the overall Excel generation and saving operation?
• Are you observing similar performance issues with lower compression levels (e.g., compression type 1-5) compared to maximum compression (type 9)?
• What is the typical file size difference between compressed and uncompressed outputs in your testing?
• Have you tested the same operation without compression (setting compression type to 0 or default) to isolate the impact of compression?
• Are there any specific memory constraints or hardware limitations in your deployment environment that might amplify these resource consumption issues?
• How does the performance scale with different numbers of rows/columns beyond the current 1500x10 test case?

@VaradS,

I simply tested your scenario/case using the following sample code in a console app with latest version/fix, Aspose.Cells for Java v26.1 (please try it). It works fine and instantly. The memory usage is minimal and time cost is less than a second.

long startTime = System.nanoTime();
Workbook workbook = new Workbook();
Worksheet sheet = workbook.getWorksheets().get(0);
for (int row = 0; row < 1500; row++) {
            for (int col = 0; col < 10; col++) {
                sheet.getCells().get(row, col).putValue("Row " + row + " Col " + col);
        }
}

OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.XLSX);
saveOptions.setCompressionType(9); // Maximum compression
workbook.save("d:\\files\\out1.xlsx", saveOptions);
long endTime = System.nanoTime();
// Calculate the duration in nanoseconds
long durationNano = endTime - startTime;
// Convert nanoseconds to seconds (as a double for precision)
double durationSeconds = (double) durationNano / 1_000_000_000.0;
System.out.println("Execution time in nanoseconds: " + durationNano);
System.out.println("Execution time in seconds: " + durationSeconds);

console output:

Execution time in nanoseconds: 739366300
Execution time in seconds: 0.7393663