thSoft / eclipse-commons

Eclipse Commons

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Speed up pdf hyperlink loading and creation

nittka opened this issue · comments

Currently the job loading the annotations blocks the hyperlink creation for the pdf page currently visible.
Annotations for all pages are loaded before the first hyperlink is created - even if the document has 100 pages and the first page is selected. This means that although the annotations may already be available (loading job is on page 10), hyperlinks for the first page are not yet created.

I guess, the best solution is as follows. Load annotations for all pages in the background (so they will be available for source2score navigation, but do not completely block links for the current page), but give preference to the page currently visible (createHyperlinkJob blocks until annotations for that page are properly loaded; loading is done in order of priority; priority for the currently selected page is raised to the top).

In the corresponding commit of pull request 10, I decided in favour of the following implementation. Rather than having one job loading annotations for all pages. The job loads annotations for one page and then schedules itself for loading the next page. If the current page is not yet processed, the create hyperlink job marks the page as having priority, so it will be picked up by the next load job.
Further, the create hyperlink job schedules the load annotations job - for scenarios where the job was cancelled by the user.

Loading annotations is still a performance bottleneck. I identified one cause and added a corresponding TODO in the source code.

I have looked for a more recent version of jpedal and came across https://github.com/IDRSolutions/maven-OpenViewerFX-src
Latest jars are currently at http://repo1.maven.org/maven2/org/jpedal/OpenViewerFX/6.9.21/
And I strongly recommend doing something in that direction!!

Within your org.jpedal plugin I wrote a simple test opening a score (score.pdf with 130+ pages from Mozart-KV250 which you added as integration test). I naively measured the execution times for instantiating PdfDecoder, opening pdf file, getting form renderer and getting annotations for each page 1..100. Getting the annotations took between 500ms (per page) on the first pages, 1-2 secons upto page 60 and then over 10 seconds per page (I never let the test come to an end). These are the times using the current jpedal jar.

I then used the OpenViewerFX jar. The test code could almost stay the same (PdfDecoder is now PdfDecoderFX...), but the execution times were incredible. With a few exceptions loading the annotations for all pages were below 50 ms per page.

Integrating the new jar into Elysium was a bit more tricky because actual (layout?) classes for javafx were needed (with just the jpedal.jar replaced, I always got a ClassNotFoundException for javafx.scene.layout.Pane) which is why I locally added JavaRE/lib/ext/jfxrt.jar (16MB) to the org.jpedal plugin in order to have it on the class path in the runtime Eclipse and added a new JFXPanel() call to the Activator start method in the o.e.u.views.pdf plugin (so that the Toolkit is initialized).
Performance-wise the result is "unbelievable". Whereas before I could watch the loadAnnotationsJob crawling through the pages, I could now hardly see the loadAnnotationsJob at all.

Awesome! Could you please provide a PR? For the JavaFX-Eclipse integration, I recommend e(fx)clipse.

Finally fixed in master. :)