jrmuizel / pdf-extract

A rust library for extracting content from pdfs
396 stars 78 forks source link

Performance: glyphnames::name_to_unicode is very slow #34

Open badicsalex opened 2 years ago

badicsalex commented 2 years ago

I have a very accent-heavy hungarian document I'm parsing, and 95% of the processing time was spent in name_to_unicode

Please consider using a HashMap or, even better, a compile-time perfect hash function. Example patch here: https://github.com/badicsalex/pdf-extract-fhl/commit/5cb9b67

badicsalex commented 2 years ago

BTW, there are a lot of duplicate entries in the map.

Grant-Brinkman commented 2 years ago

Can confirm that the suggested fix vastly improves speed. For a sample size of 60 PDFs, with most of them being multiple pages long, simply extracting text from them took 27 seconds.

After implementing this fix, and the one suggested in issue 33 my run time went down to 1 second. Highly recommend.

jrmuizel commented 2 years ago

Is it possible for you to share that or a similar document?

badicsalex commented 2 years ago

Here's a long one that's pretty good for benchmarking: http://www.kozlonyok.hu/nkonline/MKPDF/hiteles/MK13031.pdf

And a short one to benchmark font parsing: http://www.kozlonyok.hu/nkonline/MKPDF/hiteles/MK20058.pdf