Forum How do I...?

Prince and Apple Silicon M1

nico
Hi,

Does Prince run on Apple Silicon M1 and Rosetta?

Is Prince planned to be available as a universal application?
mikeday
We haven't made a build specifically for the M1 yet but I'm sure we will. :D
neochief
Hi Mike!

Any progress on this front? I see you already made a build for ARM Linux (https://www.princexml.com/forum/topic/2887/arm-builds). Can you make a build for Apple Silicon?
mikeday
We are still investigating this.
mikeday
The MacOS latest build now includes a universal binary with support for Apple Silicon! :D
nico
Nice, thank you, Mike. It works well.

I have two remarks:

1. I was a bit surprised that the universal binary is not faster than the previous versions under Rosetta. Do you think it will improve in the future?

2. The command “prince --version” returns “Prince 20220909” and this also what is displayed in the PDF author information in the PDF output file. Is it meant to be like that? I would prefer the old way “Prince 14.3 (www.princexml.com)”.
mikeday
That's odd, when we test it here on some test cases we see timings drop from 1.7s to 1.2s, what kind of timings are you seeing? Perhaps you could send me a sample document? Also are you running Prince under Docker or any other kind of virtualisation?

The version number will be "Prince 15" in the next numbered release.
nico
Hi,

I’m running Prince on a MacBook Pro (14", 2021), M1 Pro, 16 GB RAM without Docker or any other type of virtualization.

I did a little benchmarking to compare Prince 14.2 and Prince 20220909. I ran version 14.2 six times and then 20220909 also six times. This shows that Prince 14.2 is faster.

I cannot share the original document, but here are some metrics:

  • PDF is 17.9 MB on disk
  • 84 × A4 pages
  • 93 × PNG / 13.2 MB in total
  • 48 × JPG / 12.5 MB in total
  • ~120000 characters
  • ~16000 words
  • 94 tables

# Prince 14.2

2022-09-12 08:15:12   html2pdf : Convert HTML to PDF
2022-09-12 08:15:18   dT = 6s

2022-09-12 08:18:52   html2pdf : Convert HTML to PDF
2022-09-12 08:18:58   dT = 6s

2022-09-12 08:19:05   html2pdf : Convert HTML to PDF
2022-09-12 08:19:11   dT = 6s

2022-09-12 08:19:17   html2pdf : Convert HTML to PDF
2022-09-12 08:19:22   dT = 5s

2022-09-12 08:19:27   html2pdf : Convert HTML to PDF
2022-09-12 08:19:33   dT = 6s

2022-09-12 08:19:37   html2pdf : Convert HTML to PDF
2022-09-12 08:19:43   dT = 6s

# Prince 20220909

2022-09-12 08:20:58   html2pdf : Convert HTML to PDF
2022-09-12 08:21:05   dT = 7s

2022-09-12 08:21:11   html2pdf : Convert HTML to PDF
2022-09-12 08:21:18   dT = 7s

2022-09-12 08:21:22   html2pdf : Convert HTML to PDF
2022-09-12 08:21:29   dT = 7s

2022-09-12 08:21:32   html2pdf : Convert HTML to PDF
2022-09-12 08:21:39   dT = 7s

2022-09-12 08:21:43   html2pdf : Convert HTML to PDF
2022-09-12 08:21:50   dT = 7s

2022-09-12 08:21:54   html2pdf : Convert HTML to PDF
2022-09-12 08:22:01   dT = 7s

Edited by nico

mikeday
Interesting, I wonder if it could be related to PNG decoding. Is there an easy way to comment out the images? Perhaps with "img { display: none !important } * { background-image: none !important }" or something similar?
mikeday
Also, would you be able to compare with the last (non-M1) latest build:

https://www.princexml.com/download/prince-20220902-macos.zip

This will confirm that it's an architecture difference and not some other change introduced since Prince 14.
nico
Here are the results. Without images, the latest version is 20 % faster.

I commented out the images as you proposed:

img { display: none !important }
* { background-image: none !important }


# Prince 20220902
html2pdf elapsed time: 1.0 s
html2pdf elapsed time: 0.9 s
html2pdf elapsed time: 0.9 s
html2pdf elapsed time: 0.9 s
html2pdf elapsed time: 0.9 s
html2pdf elapsed time: 0.9 s
              average: 0.92 s


# Prince 20220909
html2pdf elapsed time: 0.7 s
html2pdf elapsed time: 0.7 s
html2pdf elapsed time: 0.8 s
html2pdf elapsed time: 0.7 s
html2pdf elapsed time: 0.7 s
html2pdf elapsed time: 0.8 s
              average: 0.73 s
mikeday
Ah, that's great! Would you be able to check whether it is the PNG or the JPEG images that make the difference? We couldn't find any slowdown with PNG here, but there are many different flags and image types and it could be that it's hitting one that takes libpng or libjpeg off the fast path for some reason.
nico
According to my measurements, Prince 20220909 is faster than Prince 20220902 when PNG images are not displayed and is slower in all other cases (i.e. when PNG images are displayed).

I forgot to mention that the file also contains some SVG images.


Prince 20220902 — PNG not displayed

html2pdf elapsed time: 1.6 s
html2pdf elapsed time: 1.6 s
html2pdf elapsed time: 1.5 s
html2pdf elapsed time: 1.5 s
html2pdf elapsed time: 1.5 s
html2pdf elapsed time: 1.5 s
              average: 1.53 s

Prince 20220909 — PNG not displayed

html2pdf elapsed time: 1.2 s
html2pdf elapsed time: 1.2 s
html2pdf elapsed time: 1.2 s
html2pdf elapsed time: 1.2 s
html2pdf elapsed time: 1.2 s
html2pdf elapsed time: 1.2 s
              average: 1.20 s

---

Prince 20220902 — JPG not displayed

html2pdf elapsed time: 5.9 s
html2pdf elapsed time: 5.9 s
html2pdf elapsed time: 5.9 s
html2pdf elapsed time: 5.9 s
html2pdf elapsed time: 6.0 s
html2pdf elapsed time: 5.9 s
              average: 5.92 s

Prince 20220909 — JPG not displayed

html2pdf elapsed time: 6.7 s
html2pdf elapsed time: 6.7 s
html2pdf elapsed time: 6.7 s
html2pdf elapsed time: 6.7 s
html2pdf elapsed time: 6.6 s
html2pdf elapsed time: 6.7 s
              average: 6.68 s

---

Prince 20220902 — SVG not displayed

html2pdf elapsed time: 6.0 s
html2pdf elapsed time: 6.0 s
html2pdf elapsed time: 6.0 s
html2pdf elapsed time: 6.0 s
html2pdf elapsed time: 6.0 s
html2pdf elapsed time: 6.0 s
              average: 6.00 s

Prince 20220909 — SVG not displayed

html2pdf elapsed time: 6.7 s
html2pdf elapsed time: 6.7 s
html2pdf elapsed time: 6.8 s
html2pdf elapsed time: 6.8 s
html2pdf elapsed time: 6.7 s
html2pdf elapsed time: 6.7 s
              average: 6.73 s
mikeday
Interesting, that's very helpful! If you're not able to send me any of the images, would you perhaps be able to run pnginfo on them or use a similar tool to check what kind of encoding they are using?
nico
I don’t have `pnginfo` but I made a Python script with the PIL library. The results are in the attached file.

Tell me if you need more info.

from PIL import Image
img = Image.open(img_path)
img.format
img.mode
img.size
img.width
img.height
img.palette
img.info
img.close()

  1. get_image_info.txt45.3 kB
mikeday
Thanks, we've done some more testing with images with these general characteristics but haven't been able to reproduce an obvious slowdown yet. Do you get the same result if you include those PNG images in an otherwise empty document, that's just a sequence of <img> elements?
nico
I have done some tests which show that the slowdown is noticeable with indexed color PNGs. Moreover, the effect is much more pronounced if an alpha channel is present.

The test files are attached to this post.

# Prince versions
v20220902 : last (non-M1) latest build
v20220909 : M1 build

# TEST 1
file type              : indexed color PNG
transparency           : no
time elapsed v20220902 : 0.66 s
time elapsed v20220909 : 0.72 s
time increase          : 9.0 %

# TEST 2
file type              : indexed color PNG
transparency           : yes, channel 0
time elapsed v20220902 : 1.03 s
time elapsed v20220909 : 1.46 s
time increase          : 41.2 %

  1. prince_m1_speed_test.zip56.2 kB
mikeday
Thanks, we can reproduce the issue now and will investigate.
mikeday
We have released a new latest build that embeds indexed PNG images in the PDF instead of expanding them to RGB, which should avoid the issue with libpng being unexpectedly slow on M1 and may reduce PDF file size as well.
nico
Thank you Mike, it seems to work well. Here are the results of the test files that I posted above. Note that I get the same kind of results on a real file.

file type: indexed color PNG

|                      VERSION | TRANSPARENCY | TIME ELAPSED | FILE SIZE |
|                           -: |           -: |           -: |        -: |
| last non-M1 build: v20220902 |           no |       0.68 s |    152 kB |
|                              |          yes |       1.06 s |    202 kB |
|          M1 build: v20220909 |           no |       0.74 s |    152 kB |
|                              |          yes |       1.51 s |    202 kB |
|   latest M1 build: v20221028 |           no |       0.31 s |     56 kB |
|                              |          yes |       0.31 s |     56 kB |

Edited by nico

mikeday
That's great! Thank you for the detailed feedback. :D