Image performance degradation when using threads

Hi Aspose

Could you investigate the following phenomenon: When using threads, saving a document with an image takes (on average) more time, probably because of AWT locking… Is there any remedy to this? After all, I am saving the same image all the time!

Document: (31.0 KB)
Code: (899 Bytes)
Example output for 1 and 10 thread(s):
1, AVG: 33.44111776447106
10, AVG: 79.42315369261478


Thanks for your inquiry. We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system as WORDSJAVA-1775. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.


Please tell us how many CPUs (real and virtual) do you have on your test machine? Please also provide complete statistics from 1 to 10 without gaps (i.e. for 1 thread, 2 threads, 3 threads and so on). Thanks for your cooperation.


Also, I have attached code and its results to measure performance (see (14.9 KB)). You can see that there are 4 processors on the machine we performed these test on and there are mostly no performance loses up to 4 threads. Yes, standard java and our code has some locks inside, but we think they are not critical. According to attached picture, most of the time is spent on math calculations which could be easily done parallel if an amount of threads do not exceed total amount of available processors.

So, can you please launch our performance test on your machine, check our prediction about the performance with multiple threads and let us know your findings. Thanks for your cooperation.

Here is the result on my machine:

Processors = 8

1:	1		40		68
2:	2		51		72
3:	1		52		78
4:	1		59		89
5:	1		67		109
6:	1		72		121
7:	1		79		151
8:	1		84		167
9:	2		108		188
10:	2		105		219

The question I am asking is, if I am writing the same image to pdf all the time, could you not use a cache to dramatically increase rendering performance? After all, once the image is rendered to the format needed by pdf, why is AWT even needed anymore?

Do you have other suggestions to speed up pdf generation when using images? This is a real performance issue for us in a productive system…


Thanks for the additional information. We will keep you informed of further updates.


Regarding WORDSJAVA-1775, we have inner cache for images, however it cannot be used across multiple documents. When you add an image to a document, it is converted several times to a specific format which is required by a document’s type. For example, PDF document splits an image with alpha channel into two images with data and mask. It is a part of PDF standard. We will try to find an approach how to optimize this behavior. However, in your case we can optimize your specific document. There are some rules which are applicable:

  • Image without alpha channel renders faster than similar image with alpha channel
  • Image with only black and white renders faster than similar RGB image
  • Do not have big images which will be scaled (you do not have)

We took an image from the attached document and converted it to 32/24/8 bpp. Performance test is attached (see (48.0 KB)). Results are:

  • BufferImage32: 60
  • BufferImage24: 42
  • BufferImage8: 21
  • bytes 32: 30
  • bytes 24: 25
  • bytes 8: 12

Is it acceptable for you? We received result which is 5 times faster than initial one (60 -> 12). If no, could you please describe how you generate the document?


We are waiting for your further input on this topic. Please see my previous post and share your further thoughts. Thanks for your cooperation.


Regarding WORDSJAVA-1775, we have completed the work on this issue and come to a conclusion to close this issue as “not a bug” because of lack of further information from your end. On our end, the latest version of Aspose.Words works as designed.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan