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

The minted v3.1.1 is much slower than minted2 #412

Open
hair-splitter opened this issue Oct 5, 2024 · 3 comments
Open

The minted v3.1.1 is much slower than minted2 #412

hair-splitter opened this issue Oct 5, 2024 · 3 comments

Comments

@hair-splitter
Copy link

hair-splitter commented Oct 5, 2024

My system:

  • Windows 11
  • TeX Live 2024 (updated: 2024-10-05)
  • minted v3.1.1

Contents of document.tex:

\documentclass{article}
\usepackage{minted}
\begin{document}
\begin{minted}{c}
int main() {
printf("hello, world");
return 0;
}
\end{minted}
\end{document}

Compile with pdflatex document
The compilation time: 7.74sec
The time of the second compilation (so that not only the placeholder is visible): 7.63sec

If document.tex contains:

\documentclass{article}
\usepackage[highlightmode=immediate]{minted}
\begin{document}
\begin{minted}{c}
int main() {
printf("hello, world");
return 0;
}
\end{minted}
\end{document}

Compile with pdflatex document (before that, all auxiliary and temporary files are deleted)
Compilation time: 13.31sec

If document.tex contains:

\documentclass{article}
\usepackage{minted2} % THE CHANGE IS HERE!
\begin{document}
\begin{minted}{c}
int main() {
printf("hello, world");
return 0;
}
\end{minted}
\end{document}

Compile with pdflatex -shell-escape document (before that, all auxiliary and temporary files are deleted)
Compilation time: 1.26sec

Is there a way to get the result after just one compilation when using minted v3.1.1, but just as quickly as with minted2?

@gpoore
Copy link
Owner

gpoore commented Oct 5, 2024

I think there are several different factors affecting compilation time with minted v3.1.1 versus minted2. First, v3.1.1 doesn't require shell escape because it follows LaTeX security settings, but that adds overhead because it must retrieve settings from kpsewhich. Second, v3.1.1 typically uses \ShellEscape two times more per document, once to detect configuration before the first code is highlighted and once at the end to clean temp files and the cache. This also adds overhead. There may be ways to optimize that somewhat in the future.

I'm seeing significantly faster compilation times under Windows 10, though v3.1.1 is still a good bit slower for short documents than v2.9. I suspect that part of what you are seeing may be due to antivirus or other security software. The Python libraries that are bundled with the minted v3.1.1 package are zip archives accessed via Python's zipfile. It's possible that accessing the libraries from the zip archives could trigger some sort of security scan.

I'd suggest installing the latexminted library separately, within a Python installation (something like pip install latexminted, depending on your Python installation and configuration). This will create a latexminted.exe executable. If this has priority on PATH over the latexminted.exe that is bundled with TeX Live, and you run pdflatex with -shell-escape, then the Python installation's latexminted.exe will be used instead, and that could be a way to diagnose things. (TeX Live is designed so that any executable outside the TeX installation requires -shell-escape under Windows, even if the executable is on the trusted list.)

@hair-splitter
Copy link
Author

hair-splitter commented Oct 6, 2024

Thank you very much for your reply. I will try your advice.

@gpoore
Copy link
Owner

gpoore commented Oct 13, 2024

I've done some additional testing on a few different Windows 10 machines. In the most recent case, summarized below, I got 1.8s for minted2, compared to your 1.26s, which probably indicates that your machine is much newer and faster. For the same machine, I got minted v3 times that are much faster than yours. This suggests some sort of operating system or configuration effect on performance.

                                    1st compile (s)    2nd compile (s)  
minted v3, default highlightmode      4.3                4.0
minted v3, highlightmode=immediate    6.5                4.0
minted 2                              1.8                0.6

I'm working on a few optimizations, and already have around 20% speedup for the baseline case beyond the table above. However, optimizing the code will only have a limited effect if there is some sort of additional operating system or configuration issue that is responsible for most of the slowdown.

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

No branches or pull requests

2 participants