I’m using PdfConverter
to convert word to pdf.But I find that pdfConverter very slow during the first conversion.Then It gets faster.
The response time of my spring boot application use PdfConverter
is roughly 12s -> 300ms -> 300ms. So I guess there are cache in PdfConverter
.But I don’t find them.The main different time is in PdfConverter#doConvert
->XWPFDocumentVisitor#visitore() visitBodyElements
.I don’t find cache in this class.Where is the cache.
Here is a demo code you can reporduce this situation.
PdfOptions options = PdfOptions.create();
XWPFDocument xwpfDocument;
String resourceLocation = "classpath:template/cadreTemplate-new.docx";
File template = ResourceUtils.getFile(resourceLocation);
try (FileInputStream inputStream = new FileInputStream(template)) {
xwpfDocument = new XWPFDocument(inputStream);
}
PdfConverter.getInstance().convert(xwpfDocument, new ByteArrayOutputStream(), options);
my maven dependency
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.poi.xwpf.converter.pdf-gae</artifactId>
<version>2.0.3</version>
</dependency>
- I want to know different word template need to init every time or they only need init once.
- how could I init PdfConverter to reduce my first request time in spring with an elegant way?
I try different way to find different response time.
5
See “Why GraalVM instead of plain ol’ Java?” at https://spring.io/blog/2023/09/20/hello-java-21 . GraalVM native images (ahead-of-time compilation) may allow you to massively decrease startup time.
On an sample app benchmark (Spring Petclinic), they had 34x faster startup speeds.
Image is from https://medium.com/graalvm/graalvm-for-jdk-21-is-here-ee01177dd12d
The benchmarks are for the Oracle build of GraalVM (not necessarily the same as a build of the FOSS version).