Thanks for creating and maintaining this great library!
I'm running into an issue where one particular document causes PdfPig to spin effectively forever just calling document.GetPage(int).
Debugging into the library, I determined that time is all taken in ResourceStore.LoadResourceDictionary. In particular, the loop over extGStateDictionaryToken.Data loops ~30,000 times.
This in and of itself isn't a huge issue, though, since each overall call to LoadResourceDictionary takes ~300ms to complete.
The real issue is that LoadResourceDictionary seems to be called for every single one of the page's ~4200 operations. As far as I can tell, the loads are entirely redundant in that every DictionaryToken passed to LoadResourceDictionary has the same GetHashCode() value and the same extGStateDictionaryToken.Data loop iterations. This makes the page load extremely slow.
Is there something we can do to optimize here and avoid needing to load the same dictionary over and over? FWIW the file opens quickly in Chrome.
As a side note, given that loading PDF data can be kind of unbounded even for reasonably-sized PDFs, it would be nice if PdfPig functions offered a CancellationToken so that we can bail out after a certain time period (kind of like .NET regex timeout). That seems like potentially larger and more controversial build, though.
I'd love to provide the file but unfortunately it's user-provided and not mine to share. However, I can easily test any proposed fix.
Thanks for creating and maintaining this great library!
I'm running into an issue where one particular document causes PdfPig to spin effectively forever just calling
document.GetPage(int).Debugging into the library, I determined that time is all taken in
ResourceStore.LoadResourceDictionary. In particular, the loop overextGStateDictionaryToken.Dataloops ~30,000 times.This in and of itself isn't a huge issue, though, since each overall call to
LoadResourceDictionarytakes ~300ms to complete.The real issue is that
LoadResourceDictionaryseems to be called for every single one of the page's ~4200 operations. As far as I can tell, the loads are entirely redundant in that everyDictionaryTokenpassed toLoadResourceDictionaryhas the sameGetHashCode()value and the sameextGStateDictionaryToken.Dataloop iterations. This makes the page load extremely slow.Is there something we can do to optimize here and avoid needing to load the same dictionary over and over? FWIW the file opens quickly in Chrome.
As a side note, given that loading PDF data can be kind of unbounded even for reasonably-sized PDFs, it would be nice if PdfPig functions offered a CancellationToken so that we can bail out after a certain time period (kind of like .NET regex timeout). That seems like potentially larger and more controversial build, though.
I'd love to provide the file but unfortunately it's user-provided and not mine to share. However, I can easily test any proposed fix.