158 points · by RedMindZ · 1d ago · 60 comments
I thought that if we simply converted those paths into triangles the GPU could just blast through them. Today, after more than 5 years and 3 iterations in 3 different languages, I would like to share with you the 3rd iteration of my PDF viewer: Named "Pryzmera", I wrote it by hand with the goal to render those CAD PDFs at interactive frame rates, and with the intention to make every feature as fast as I could possibly imagine it to be.
When Pryzmera opens a document, it first starts by interpreting each page. As a page is interpreted, it generates small clipping & tessellation jobs that run in parallel. Clipping & tessellation is performed by Pryzmera's own tessellator and produces the initial geometry for the page. This geometry is then collected and jointly optimized to produce a final GPU representation that mostly consists of colored/textured triangles. The representation is completely static, which in turn makes rendering performance (FPS) almost static, even when the view changes (e.g. panning/zooming/rotating). Once the representation is uploaded to the GPU, rendering a page typically requires only 3-4 draw calls.
On my machine (GTX1080/i7-5820k), Pryzmera can render my father's CAD PDFs at hundreds (and sometimes thousands) of frames per second. Compared to Adobe Acrobat:
- Loading is about 2-10x faster (depending on how Acrobat is feeling on the day)
- Rendering is about 1200-5700x faster (depending on Pryzmera's graphics settings)
- Text search is about 100x faster (although it's hard to measure Acrobat's performance here)
- And this trend continues...
If you would like to test the performance yourself, you can press F8 to bring up the render stats, including FPS and VRAM usage breakdown; You can try this stress-test file I made that is rather representative of the PDFs generated by CAD software: https://pryzmera.com/stress_test.pdf
And if you are curious about any of the technical details, or anything else, ask away!
- There's plenty of competition: NitroPDF, PDF Xchange and others are probably your primary competition. Adobe is the gorilla but I avoid Adobe at all costs unless there's specifically a DRM'd PDF that requires acrobat with a plugin.
I would certainly be interested in the GPU acceleration and getting more out of that.
Currently the framerate is uncapped to minimize input latency. If Pryzmera doesn't receive any input it stops rendering, so it shouldn't waste system resources (except RAM) while you are not using it. You should be able to see the FPS freeze and CPU/GPU utilization go to zero if you stop moving your mouse (it could take a few seconds). If that is not the case for you, there might be something in your system that makes Pryzmera keep rendering while idle (this happens to me when task manager is open), or there might be a bug I should fix.
I already got multiple requests to add annotation editing, I know its really important in the field, but this is a deep complexity pit and Pryzmera is already very complicated, so it's going to be a major challenge to implement. I hope I will manage to solve that as well, but that would probably be in the distant future.
I hope it can serve others as well!
For a PDF viewer, fidelity matters much more than rendering speed. Imagine using it to open CAD PDFs as you suggested, only to realize a few months later that sections of some files silently failed to render, by which point the ship has sailed.
Relying on a renderer maintained by a single person or even a small team carries significant risks. There are too many things that can go wrong.
For example, pdf.js (which powers Firefox) uses a test suite with 1,579 files and growing: https://github.com/mozilla/pdf.js/tree/master/test/pdfs
As for visual features Pryzmera currently doesn't support, the biggest one is probably shading; it's very rare in my test suite, but I will probably add support in the future, I just haven't got to it yet. Other visual features like paths, images, text, image masks and transparency are fully supported.
Lastly, I would like to add that fidelity is not absolutely everything: when you can't open a PDF, it doesn't help that it will eventually render correctly. Effectively you are not getting any render at all. Pryzmera does its best to render as close to the spec as possible, but is willing to sacrifice some visual fidelity (for example, by flattening curves into multiple line segments) in order to achieve orders of magnitude better performance. And if something does fail to render, it should appear in the logs, excluding bugs of course.
On Pryzmera's side, the same way it renders to the window, it can render to an image file instead (PNG). On the "ground truth" side, I use mutool (based on MuPDF) to render the same PDF into another image file. Both renders are configured to use the same resolution, and then they can be compared pixel-by-pixel. Pixels are simply 3 numbers, representing the intensity of the red, green, and blue colors in the pixel. Each one of those can be directly compared to the same color in the other pixel by simply calculating their absolute difference (AKA |red1 - red2|). You can also use other functions here, like squared distance and such. All of the differences are summed to give you the error for each pixel, and then you can measure different metrics, like the pixel with the biggest error in the image, or the average pixel error for the image.
One note about "ground truth": When it comes to PDF rendering, the specification is incredibly long and complicated, which means there is basically not a single renderer that renders PDFs 100% correctly, even Acrobat likely has bugs. Thus, the output for each renderer is usually slightly different, especially around weird edge cases. For that reason, "whatever Acrobat does" has often times become the effective specification.
And if you have any other questions, please don't hesitate to ask!
I'm glad people are still trying to make things better. It's a great irony that as computers get faster and faster, software still manages to get slower and slower.
I believe all the software we use can be great, and Pryzmera is my one contribution towards that. Whether it is great or not is left up to everyone's judgement, but its the best I can do.
Also on a safety note, are you excluding the exploit vulnerable parts of PDF support?
If you refer to the accuracy of rendering, it is effectively identical on my test suite up to minor differences in anti-aliasing and such; I gave a more detailed answer in another comment.
If you refer to rendering performance (FPS), then it is hundreds to thousands of times faster, although I don't have exact benchmarks; I talked about it some more in the comment asking about SumatraPDF.
As for safety, I have to be honest and say that I have not paid much attention to it specifically. I am using Rust, and I utilize the type system as much as I can to ensure all cases are handled and there are no panics or memory corruptions. Only MuPDF directly interfaces with the PDF, so I hope that given its age it has patched most vulnerabilities. I have also disabled JS in the MuPDF build and I assume that is where most vulnerabilities would be. If there is something else I should be aware of, let me know.
For now, there is a portable version on the downloads page (https://pryzmera.com/downloads/), and one of my friends ran it on ubuntu with wine, and it seemed to work fine. As for Mac, another friend tested with wine on Mac and it didn't work at all; Maybe it would work with CrossOver? But I don't know anything about Windows emulation on Mac.
If you are interested in trying it on a non-windows system, I would love to hear if it works well for you!
I did my best to tune text rendering to look as good as it can be, but it's certainly not perfect. You can try raising the text rendering quality from the graphics settings (lets say to 64), reload the document with F5, and see if it looks better.
If you are talking about performance, while I haven't benchmarked SumatraPDF specifically, it is using MuPDF under the hood both for parsing and rendering. I actually modified my MuPDF to load significantly faster in specific situations, so Pryzmera and SumatraPDF should be competitive on loading speed. For rendering performance, I am familiar with MuPDF's rendering performance and would confidently estimate that Pryzmera renders hundreds or thousands of times faster compared to SumatraPDF. Sadly I don't have exact benchmarks, so I hope my best estimate will suffice here.
If you are talking about other features, I am frankly not sure, I don't use SumatraPDF and only have a rough idea of what it offers, so I regrettably cannot inform you there.
Sorry, but that is not acceptable for a perpetual license.
And regardless, as far as I know, it is mathematically impossible to implement both an offline license that never calls to the server and transferable activations. The reason being that if you never verify the license with the server, someone could take a snapshot of the machine, transfer the license, then roll back the machine, which would yield an infinite number of activations.
It was far more important to me that Pryzmera would keep working permanently even if one day me and the server disappeared. This is software that is completely independent of the server and will keep running indefinitely, which means it also works in air-gapped systems.
If you have a better suggestion for how to implement licensing, please let me know.
And if you allow offline activation, I don’t see how you can control the number of activations anyway.
I would be borderline willing to purchase a PDF viewer for 50€ if it is really good (it’s already a steep price) despite being limited in terms of updates. But being limited in how many PCs I can use it on over time because you don’t trust your paying customer to not give it away is too off-putting for me.
The way offline activation works is by enabling you to reach the server from a different computer that does have an internet connection, but it is mostly orthogonal to not requiring checking in with the server after activation. After activation is performed, Pryzmera has a local license that never requires it to check in with the server, which is why it is not transferrable.
The issue is not that I don't trust my paying customers, it's that in all likelihood someone will abuse the system and will resell a single key as many times as they can. Maybe I worry too much about this option, but for now this path seems reasonable to me.
Sample Link (West Mt. Rainier 7.5min): https://prd-tnm.s3.amazonaws.com/StagedProducts/Maps/USTopo/...
This PDF is mainly composed of a large image (around 1GB uncompressed, very close to my stress test) and relatively few vector paths, Pryzmera renders it at about 300FPS on my machine.
Perhaps then you should market it as "Fast PDF for people who love CAD" or something. Then you might catch the attention of the people for whom this solves a problem
Aiming generally at everyone, certainly I'm like "meh, PDF seems fast enough".
I wish you good luck finding customers.
PDF X-Change comes to mind. It handles the linked stress PDF pretty well.
EDIT: I wonder if OP is an handmade hero guy? There's been a bunch of pretty cool products from that community: Zeiger, Blick, FilePilot, ...
And yes, I am quite fond of the handmade network :)
https://github.com/koziserek/ffss - saying so, because this feature landed exatly today ;)
the stress test renders in < 3 seconds on my m5 max in pdfcraft (which is open source). Not sure I would ever pay $60 for a closed-source app to "speed it up," especially given how contrived that stress-test PDF is.
> GTX1080/i7-5820k
Yeah, there's your problem. Computers have gotten substantially faster in the last dozen years. I can't say I've felt that a PDF (regardless of how complex) has been slow during that time.
If I had an older computer, and my field of work required me to open extremely complex PDFs and my two options were 1) buying a $60 software 2) dropping $5K in a new computer... I think I'd chose the first.
And as far as my hardware is concerned, not everyone has the latest hardware. But even old hardware is so incomprehensibly fast, there is no reason it shouldn't render everything at least at 60 FPS or higher.
If you don't struggle with slow PDFs, that's great; Pryzmera is probably not for you, but in architecture and related fields this is a huge problem.
Three seconds can get to be a real pain if you do it a lot.
Always room for things to go faster.