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

Feature request: speed-up Sphinx build of LaTeX files #4803

Closed
jfbu opened this issue Mar 30, 2018 · 2 comments
Closed

Feature request: speed-up Sphinx build of LaTeX files #4803

jfbu opened this issue Mar 30, 2018 · 2 comments
Assignees
Milestone

Comments

@jfbu
Copy link
Contributor

jfbu commented Mar 30, 2018

When building Sphinx own documentation at my locale, it currently needs about 12.5s for the HTML build, and about 57s for the PDF build. From this, about 48s are needed for Sphinx build itself and 9s for pdflatex producingt PDF from the LaTeX file. Most of the 48s are spent into the "writing phase".

Perhaps there is something suboptimal here and it should be made faster if possible.

Environment info

  • OS: Mac OS 10.9.5 on a 2,8 GHz Intel Core i7 with 16 Go 1333 MHz DDR3 memory
  • Python version: 3.6.4
  • Sphinx version: 1.8.0+/9a2092759
  • TeXLive 2018 with self-built binaries
@jfbu jfbu added this to the 2.0 milestone Mar 30, 2018
@tk0miya
Copy link
Member

tk0miya commented Mar 30, 2018

I investigated it with following patch:

diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py
index 9c1c50c5b..6a25c2db5 100644
--- a/sphinx/builders/__init__.py
+++ b/sphinx/builders/__init__.py
@@ -396,7 +396,12 @@ class Builder(object):
         self.finish_tasks = SerialTasks()

         # write all "normal" documents (or everything for some builders)
+        from cProfile import Profile
+        p = Profile()
+        p.enable()
         self.write(docnames, list(updated_docnames), method)
+        p.disable()
+        p.dump_stats('writing.prof')

         # finish (write static files etc.)
         self.finish()

And I got the following profile. It says renumber_footnotes is a very slow.

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000  113.261  113.261 /Users/tkomiya/work/sphinx/sphinx/builders/latex.py:115(write)
        1    0.001    0.001  109.959  109.959 /Users/tkomiya/work/sphinx/.tox/py27/lib/python2.7/site-packages/docutils/writers/__init__.py:65(write)
        1    0.000    0.000  109.949  109.949 /Users/tkomiya/work/sphinx/sphinx/writers/latex.py:178(translate)
11856071/1346   43.959    0.000  108.620    0.081 /Users/tkomiya/work/sphinx/.tox/py27/lib/python2.7/site-packages/docutils/nodes.py:207(traverse)
        1    0.000    0.000  108.001  108.001 /Users/tkomiya/work/sphinx/sphinx/writers/latex.py:233(apply)
        1    0.010    0.010  107.873  107.873 /Users/tkomiya/work/sphinx/sphinx/writers/latex.py:286(renumber_footnotes)
 84801230   24.936    0.000   24.936    0.000 {isinstance}
12398557/1083   16.669    0.000   21.848    0.020 /Users/tkomiya/work/sphinx/.tox/py27/lib/python2.7/site-packages/docutils/nodes.py:190(_fast_traverse)
 18363833   14.712    0.000   21.496    0.000 /Users/tkomiya/work/sphinx/.tox/py27/lib/python2.7/site-packages/docutils/nodes.py:565(__getitem__)
      264    0.046    0.000   21.067    0.080 /Users/tkomiya/work/sphinx/sphinx/writers/latex.py:288(is_used_number)
 11809912    4.925    0.000    9.209    0.000 /Users/tkomiya/work/sphinx/sphinx/writers/latex.py:305(is_footnote_ref)
        1    0.000    0.000    3.221    3.221 /Users/tkomiya/work/sphinx/sphinx/builders/latex.py:169(assemble_doctree)

@tk0miya tk0miya modified the milestones: 2.0, 1.7.3 Mar 30, 2018
@tk0miya tk0miya self-assigned this Mar 30, 2018
tk0miya added a commit to tk0miya/sphinx that referenced this issue Apr 14, 2018
@tk0miya
Copy link
Member

tk0miya commented Apr 15, 2018

Fixed by #4843
Thank you always!

@tk0miya tk0miya closed this as completed Apr 15, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants