Skip to content

Commit

Permalink
#396 Profiling performance case for border radius being very slow. [c…
Browse files Browse the repository at this point in the history
…i skip]
  • Loading branch information
danfickle committed Oct 20, 2019
1 parent c8a3010 commit 8ef7783
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,25 @@ public static String tableRows(int howMany) {
.mapToObj(i -> tr)
.collect(Collectors.joining("\n", hdr, ftr));
}

/**
* Performace case for:
* Issue 396 - CSS border-radius makes pdf rendering very slow.
* Caused by Area constructor being very slow (according to VisualVM).
*
*/
public static String borderRadius(int howMany) {
final String hdr = "<html><head><style>div.avatar { margin-left: auto; margin-right: auto; height: 200px; width: 160px; " +
"background-size: cover; background-position: center center; background-repeat: no-repeat; " +
"border-radius: 4px;" +
"background-image: url(demos/images/flyingsaucer.png); }" +
"</style></head><body>";
final String div = "<div class=\"avatar\"></div>";
final String ftr = "</body></html>";

return IntStream.range(0, howMany)
.mapToObj(i -> div)
.collect(Collectors.joining("\n", hdr, ftr));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ private static void run(String name, String html) throws Exception {

Thread.sleep(20_000);

System.out.println("Beginning actual case now...");

long start = System.currentTimeMillis();
ByteArrayOutputStream baos = new ByteArrayOutputStream(0xffff);
PdfRendererBuilder builder = new PdfRendererBuilder();
builder.withHtmlContent(html, null);
builder.withHtmlContent(html, PerformanceCaseGenerator.class.getResource("/").toExternalForm());
builder.toStream(baos);
builder.useFastMode();
builder.run();
long end = System.currentTimeMillis();

System.out.println("Profiling case took " + (end - start) + "milliseconds.");
System.out.println("Profiling case took " + (end - start) + " milliseconds.");

Files.createDirectories(Paths.get("target/test/profiling/"));
Files.write(Paths.get("target/test/profiling/" + name + ".pdf"), baos.toByteArray());
Expand All @@ -33,7 +35,8 @@ public static void main(String... args) throws Exception {
// Just uncomment the one you want to profile...

//run("paragraphs", PerformanceCaseGenerator.paragraphs(80_000));
run("table-rows", PerformanceCaseGenerator.tableRows(50_000));
//run("table-rows", PerformanceCaseGenerator.tableRows(50_000));
run("border-radius", PerformanceCaseGenerator.borderRadius(30_000));
}

}

0 comments on commit 8ef7783

Please sign in to comment.