Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide multiple lazy-loaded backends for SVGs #57

Merged
merged 2 commits into from
Aug 19, 2020

Conversation

mirkobunse
Copy link
Contributor

SVGs can now be produced with multiple backends:

  • Poppler_jll lately was the default. It works on all platforms, but requires julia-1.3 and is slow to load.
  • pdf2svg was the former default. The user has to have this library installed.
  • dvisvgm always was the fall-back solution if tikzUsePoppler() or tikzusePDF2SVG() was explicitly set to false by the user.

The original code for the dvisvgm fallback was somehow broken; I fixed it when implementing this PR.

Providing different backends has the advantage of (potentially) faster loading times that do not loose compatibility across platforms. We have already discussed the slow loading times and potential solutions: JuliaTeX/PGFPlots.jl#130

using TikzPictures now checks whether pdf2svg is installed. If so, it uses the corresponding backend and the package loads quickly. If pdf2svg is not installed, the package uses Poppler_jll instead, which results in a longer loading time. The dvisvgm backend is only used if explicitly set by the user. An open point of discussion is whether Poppler_jll should have precedence over dvisvgmin this sense.

using TikzPictures # loads a default backend

# set any of the backends explicitly
svgBackend(PdfToSvgBackend()) # default if pdf2svg is installed
svgBackend(PopplerBackend()) # default otherwise
svgBackend(DVIBackend()) # only used if set explicitly this way

Loading times

pdf2svg is already installed on my local machine, so loading TikzPictures.jl will be fast there. I can set the backend to poppler manually, afterwards, to see what loading Poppler_jll does. I tried this with julia v1.3 and v1.5, the last of which has improved loading *_jll packages a lot.

command v1.3 v1.5
@time using TikzPictures 0.4 seconds 0.3 seconds
@time svgBackend(PopplerBackend()) > 9 seconds 3.9 seconds

Testing

Travis CI is testing PR currently on julia v1.0 (yes, it works again), v1.3, and v1.5. The only platform, however, is Linux. Poppler_jll should work everywhere, but I have not yet figured out how to tell Travis to install texlive etc on Mac OS and Windows. Any improvement of the .travis.yml in this direction is warmly welcome!

@mirkobunse
Copy link
Contributor Author

Update: I also checked @time using PGFPlots:

julia loading time without this PR and with this PR
v1.3 15.9 seconds 9.7 seconds
v1.5 10.4 seconds 8.9 seconds

@mirkobunse
Copy link
Contributor Author

An alternative to this PR could be to set up a MinimalPoppler_jll which only offers pdftocairo and omits the other functionality that slows down loading Poppler_jll. Would make multiple backends completely unnecessary. Might be worth a discussion in the Yggdrasil repository.

@mykelk mykelk merged commit f586d07 into JuliaTeX:master Aug 19, 2020
@mykelk
Copy link
Member

mykelk commented Aug 19, 2020

This looks great! Thank you for your contribution!

@mirkobunse
Copy link
Contributor Author

Sure, you're welcome!

Still, I think extending the .travis.yml to test on Mac and Windows would be great. Do you know someone who can do this?

@mykelk
Copy link
Member

mykelk commented Aug 19, 2020

I don't. I wanted to be able to do this for a while, but hadn't had luck. Fortunately, my PhD students use a mixture of Windows/Mac/Linux, and so they should be able to identify a potential issue---but it would be nice to have this part of travis.

@mirkobunse
Copy link
Contributor Author

Beautiful, feel free to mark me in any such issue.

In the meantime, I found out that my other suggestion, to spin up a MinimalPoppler_jll, would likely not improve the loading time much. Fortunately, we can hope for a massive improvement in julia-1.6. See JuliaPackaging/Yggdrasil#908 (comment)

If Poppler_jll is fast in 1.6, we can easily change the default SVG backend accordingly.

@mykelk
Copy link
Member

mykelk commented Aug 19, 2020

I'm so looking forward to 1.6. ;-)

@PallHaraldsson
Copy link

PallHaraldsson commented Oct 16, 2020

You mean this bit fast?

julia> @time using Poppler_jll
  0.000157 seconds (102 allocations: 11.688 KiB)

while, still not optimal (maybe you need to check on brand-new master and/or check/fix invalidations)
julia> @time using PGFPlots
  5.708749 seconds (7.53 M allocations: 504.851 MiB, 3.49% gc time, 21.08% compilation time)

@mykelk
Copy link
Member

mykelk commented Oct 17, 2020

That looks pretty fast to me! ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants