Performance and memory problem in 7.6.0

After migration from 7.1.2 to 7.6.0 We found the next problem.
Operations with cells.toImage were become too long and too many memory.
The saving word with many images in PDF, HTML and docx.
I reproduced it as conversion the excel with 300 images to PDF.


private static void convertChartsFromFile() throws Exception {
Workbook workbook = new Workbook(“big.xlsx”);
SaveOptions saveOptions = new PdfSaveOptions();

Document document = new Document();
DocumentBuilder builder = new DocumentBuilder(document);
ChartCollection chartCollection = workbook.getWorksheets().get(0).getCharts();
final long start = System.currentTimeMillis();
for (int i = 0; i< chartCollection.getCount(); i++) {
ByteArrayOutputStream pictureBytes = new ByteArrayOutputStream();
ImageOrPrintOptions imageOptions = new ImageOrPrintOptions ();
imageOptions.setImageFormat( ImageFormat.getPng());
imageOptions.setHorizontalResolution( (int) (AsposeUtility.EXCEL_CHART_WIDTH * AsposeUtility.PIXELS_TO_POINTS) );
imageOptions.setVerticalResolution( (int) (AsposeUtility.EXCEL_CHART_HEIGHT * AsposeUtility.PIXELS_TO_POINTS) );
Chart chart = chartCollection.get(i);
chart.toImage( pictureBytes, imageOptions );
byte[] data = pictureBytes.toByteArray();

// Create image by bytes
BufferedImage image = ImageIO.read(new ByteArrayInputStream(data));
builder.insertImage(image);
final long end = System.currentTimeMillis();
System.out.println("Count: " + i + “, Time: " + ((end - start)/1000f) + " sec”);

}

long startSave = System.currentTimeMillis();

document.save(“big_from_excell7.1.6.pdf”, com.aspose.words.SaveFormat.PDF);
System.out.println(“Save. Time: " + ((System.currentTimeMillis() - startSave)/1000f) + " sec”);
}

The result for 7.1.2
conversation images - Count: 299, Time: 50.676 sec
the saving all documents - Save. Time: 10.908 sec

The result for 7.6.0
conversation images - Count: 299, Time: 351.774 sec
the saving all documents - Save. Time: 82.588 sec
The source excel is “big.xlsx”.
The usage of memory in 7.1.2 you can see in "memory7.1.2.png"
The usage of memory in 7.1.2 you can see in “memory7.6.0.png”

Hi,


Thanks for the sample files and sharing some details.

Please separate the issue from Aspose.Words component. I have tested your scenario/ case a bit. I used your sample code with a few adjustment to work with Aspose.Cells for JAVA APIs only with our latest version/fix: Aspose.Cells for Java v7.6.1.5, it works fine and efficiently as well.

Sample code:
Workbook workbook = new Workbook(“big.xlsx”);
SaveOptions saveOptions = new PdfSaveOptions();

ChartCollection chartCollection = workbook.getWorksheets().get(0).getCharts();
final long start = System.currentTimeMillis();
int i;
for (i = 0; i< chartCollection.getCount(); i++) {
ImageOrPrintOptions imageOptions = new ImageOrPrintOptions ();
imageOptions.setImageFormat( ImageFormat.getPng());
Chart chart = chartCollection.get(i);
chart.toImage( “f:\files\performance1\big_” + i + “.png”, imageOptions );


}

final long end = System.currentTimeMillis();
System.out.println("Count: " + i + “, Time: " + ((end - start)/1000f) + " sec”);

Here is my console output for your reference:

Count: 300, Time: 20.45 sec

So, it only takes 20.45 sec on my Windows 8 pc. Also, the memory consumption is normal.


Please try our latest version/fix:Aspose.Cells for Java v7.6.0.5.

If you still find the issue, please create a separete JAVA program (runnable) that should use only Aspose.Cells APIs to reproduce the issue on our end. Also provide your environment details, OS, JDK version, RAM etc. We will check it soon.



Thank you.

Hi,
it’s strange problem.
with cells version 7.6.0.5 memory is ok! But time isn’t good.
Yes it’s integration problem, We uses words “Implementation-Version: 10.3.0.0” too long time.
We changed only cells library and have these effect. Simple generation many png-s is fine.
I modified my code with generation toImage in the file and after it read it and insert in the file.
But for cells 7.1.2 cells the inserting in document 50 seconds and the saving pdf needs 11 seconds
for cells 7.6.0.5 cells the inserting in document 368 seconds and the saving pdf lead to OutOffMemory in the last attempt.
I think may be words uses cells code into the saving.

Hi,


Well, it might be integration issue but I am not sure about it. I just want to make sure you separate the issue for Aspose.Cells, so I run the image generation code using Chart to Image feature provided by Aspose.Cells to save several images to check its performance and memory leakage. I could not find the issue with our latest version/fix: Aspose.Cells for Java v7.6.0.5. You may run my sample code to check if it works fine on your end.

Thank you.

Hi,
I found the problem, it’s scaling. Your code excluded set width and height.
If width and height are used it lead to the problem.
I think, I can find workaround.
My opinion the scaling in 7.6.0 is worse then in 7.1.2 by performance and memory. It’s critical for a big document.
thank you for your help.

Hi,


"I found the problem, it’s scaling. Your code excluded set width and height.
If width and height are used it lead to the problem"

Could you provide me runnable sample code (same as mine) here, you may add the lines to set width/height to my code accordingly , it will help us to evaluate your issue more precisely so that we could analyze and fix your issue in latest versions of the product.

Thank you.

The next code


Workbook workbook = new Workbook(“big.xlsx”);

ChartCollection chartCollection = workbook.getWorksheets().get(0).getCharts();
System.out.println("Create pngs: ");
final long start = System.currentTimeMillis();
int i;
for (i = 0; i< chartCollection.getCount(); i++) {

ImageOrPrintOptions imageOptions = new ImageOrPrintOptions ();
imageOptions.setImageFormat( ImageFormat.getPng());

//critical parameters
imageOptions.setHorizontalResolution( (int) (700 * 0.75) );
imageOptions.setVerticalResolution( (int) (400 * 0.75) );


Chart chart = chartCollection.get(i);
chart.toImage( “\big_” + i + “.png”, imageOptions );
final long end = System.currentTimeMillis();
System.out.println("png Count: " + i + “, Time: " + ((end - start)/1000f) + " sec”);

}

final long end = System.currentTimeMillis();
System.out.println("png Count: " + i + “, Time: " + ((end - start)/1000f) + " sec”);


setHorizontalResolution” and “setVerticalResolution” hit performance in 7.6.0 and (7.6.0.5).
If they are commented then it’s all right.

Hi,


I used your sample code (in previous post). I finally got the approx. 133 seconds to complete the 300 images’ rendering task.
png Count: 300, Time: 133.321 sec

What is the result on your end?

Thank you.

Hi,
the same value 131 seconds for 300 images for 7.6.0.5 cells.
But it’s 25.8 seconds for 300 images for 7.1.2.
Well I found the next details. We used big resolution 525x300 ( I think it’s dpi) for show text of legends. We hove another problem if resolution is default (96 dpi) then it leads to the text of legends is unreadable.
We solved it by set resolution 525x300 dpi. See “Sample with resolution.png” for 7.1.2.
But if I set to default 96x96 it leads to “
Sample without set resolution.png” for 7.6.0.5(7.6.0).
Unfortunately our trick code is brocken by migration to new version.
Now I find chart.getLegend().getFont().setSize(24); but it has any side effects.

Hi,


Thanks for providing further details and screen shots.


We need to look into your issue as it takes more time and memory when we use to set resolution as per your sample code. We also need to also check as it was used to work more efficiently in the older version i.e. v7.1.2, where it takes less time and memory. I have logged a ticket with an id “CELLSJAVA-40656” for your issue. We will look into your issue soon.

Once we have any update on it, we will let you know here.

Thank you.

Hi,


We have analyzed your issue further. In new version/fix: v7.6.0.x, we modified 2 issues for the PNG image format type.

1) Firstly, now (by using the new version/fix) the PNG image looks
more clear as the quality value is improved (the default value is 100), whereas in v7.1.2
the value is lesser than 80.

2) Secondly, the size of the images are dynamic, it will be changed with the dpi accordingly when you set resolution. For example, if the width of the original
chart is 100 pixels, when you set resolution to 2*96, the width of generated
chart’s png will be 200 pixels. So, consequently it would be a bit slower than the older version.

We suggest you don’t need to set resolution, generate EMF format for the image instead. When you insert to word, you may enlarge the size of the generated chart’s emf. For example, the insertion APIs in the Word is:

InsertToWord(targetWidth,
tartgetHeight, image)
,
Now, you may write it as:
IndertToWord(2 * originalChartWidth, 2
  • originalChartHeight, image)
. At the same time, set the text antialiasing of the chart by using, e.g
ImageOrPrintOptions.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON)


Hope, this helps.

Thank you.

Hi,

We have also tested the setSize(int value) method. It has no problem. Please find attached the zip archive that contains the resultant files and code segments.

Thank you.

Hi,
I wrote about the methods:

imageOptions.setHorizontalResolution( (int) (700 * 0.75) );
imageOptions.setVerticalResolution( (int) (400 * 0.75) );

Hi,


As we told you in one of my previous reply the size of the images are dynamic (in rendering to image files) and these would be changed with the DPI accordingly when you set resolution. If you set the resolution, consequently it would be a bit slower than the older version as we did enhance the resolution (in the newer versions) already when rendering to image files. So, we suggest you don’t need to set resolution, you may generate EMF format for the image instead also.

Thank you.