You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Chinese translations for HTML take over an hour each #209
Filtering the recent HTML rebuilds to Chinese only, we see that the average build takes 1h 6m 43s, with the shortest at 54m 25s and longest at 1h 29m 58s. This is far out of line of every other language, which take under five minutes on average. For each Python version, one Chinese build takes longer than all other languages put together.
Not much a contribution, but just to mention that these build times are far from e.g. Sphinx's own translated docs build. See sphinx-zh-cn (6 minutes or less) and sphinx-zh-tw (3 minutes or less)
@AA-Turner is it possible to produce a list of the timestamps on the written files to narrow in a bit further than library/wsgiref .. tutorial/interactive to identify elapsed-time outliers?
if combining the logs and the stat metrics, you'll get
# from stat
1728441249 :2024-10-09 02:34:09.701973645 +0000 ./tutorial/interactive.html
# from logs
2024-10-09 02:34:09,642 DEBUG zh-tw/3.14: >>>> writing output... [ 85%] library/winsound .. tutorial/inputoutput
# from stat
1728439961 :2024-10-09 02:12:41.535201139 +0000 ./tutorial/inputoutput.html
1728439961 :2024-10-09 02:12:41.479200810 +0000 ./tutorial/index.html
...
1728439959 :2024-10-09 02:12:39.823191091 +0000 ./library/wsgiref.html
1728439959 :2024-10-09 02:12:39.760190721 +0000 ./library/winsound.html
# from logs
2024-10-09 02:12:39,710 DEBUG zh-tw/3.14: >>>> writing output... [ 77%] library/textwrap .. library/winreg
# from stat
1728439436 :2024-10-09 02:03:56.039080078 +0000 ./library/winreg.html
1728439435 :2024-10-09 02:03:55.981079719 +0000 ./library/windows.html
I wonder what does the timestamp in 1728441249 :2024-10-09 02:34:09.701973645 +0000 ./tutorial/interactive.html stands for? is it HTML file creation time or last modified time?
If the timestamp stands for file creation time (and I assume sphinx-build appends the content to the file after the file is created and induces the gap), those timestamps would then make sense to me.
This reveals that the vast majority (93%) of the build duration was spent in SearchChinese.stem. After playing around with PyStemmer, it turns out there's a much more mundane explanation. SearchChinese.latin_terms is a collection of latin terms that we might want to avoid stemming. The list survives for the duration of the build and grows to be around 53,700 elements long.
SearchChinese.stem internally uses word in self.latin_terms to check membership, and hence we get appalling performance as list membership testing is $O(n)$. Switching to set membership gives $O(1)$.
With sphinx-doc/sphinx#12995, IndexBuilder.feed() 'only' takes 24% of build duration. The slowness is almost entirely due to jieba, as on a build without it installed the method takes 1.3%.
Variant
.feed() duration
Baseline
93% (18m23s)
Baseline with Jieba
96% (35m38s)
Set terms
3.1% (2.4s)
Set terms with Jieba
24% (24.1s)
@mattwang44 -- do you know of any better Chinese segmenters than Jieba? It hasn't been released for four years, and is quite slow.
https://github.com/Droidtown/ArticutAPI: It's an API SDK (communicate with backed services) with a limited free quota (2k Chinese characters per hour), registration required.
I wonder what role does the tokenizer play in the Sphinx? Does it affect the performance of text searching (from the search bar on the doc)?
I think without it the search is worse (original PR sphinx-doc/sphinx#2170). You could try building a copy of the zh-TW translation with and without Jieba installed and see if the search results for a chinese term are meaningfully different?
Latest times below. Prior to Sphinx 8.1, zh-TW took 1h 28m 16s. Now it takes 5m 41s, which is a pretty decent improvement (~15.5x). Estimated time for a full rebuild loop is now 60 180 minutes, I'll keep an eye on it.
A
Build times (HTML only)
Start
Version
Language
Build
Trigger
2024-10-10 08:16 UTC
3.14
en
2m 50s
Doc/ has changed
2024-10-10 08:18 UTC
3.14
es
6m 44s
Doc/ has changed
2024-10-10 08:25 UTC
3.14
fr
5m 55s
Doc/ has changed
2024-10-10 08:31 UTC
3.14
id
5m 47s
Doc/ has changed
2024-10-10 08:37 UTC
3.14
it
4m 49s
Doc/ has changed
2024-10-10 08:42 UTC
3.14
ja
7m 27s
new translations
2024-10-10 08:49 UTC
3.14
ko
6m 7s
Doc/ has changed
2024-10-10 08:55 UTC
3.14
pl
3m 42s
Doc/ has changed
2024-10-10 08:59 UTC
3.14
pt-br
6m 31s
new translations
2024-10-10 09:06 UTC
3.14
tr
6m 41s
Doc/ has changed
2024-10-10 09:12 UTC
3.14
uk
8m 50s
new translations
2024-10-10 09:21 UTC
3.14
zh-cn
1h 10m 19s
Doc/ has changed
2024-10-10 10:31 UTC
3.14
zh-tw
1h 28m 16s
Doc/ has changed
2024-10-10 12:00 UTC
3.13
en
4m 41s
Doc/ has changed
2024-10-10 12:04 UTC
3.13
es
6m 47s
Doc/ has changed
2024-10-10 12:11 UTC
3.13
fr
8m 24s
Doc/ has changed
2024-10-10 12:20 UTC
3.13
id
6m 48s
Doc/ has changed
2024-10-10 12:26 UTC
3.13
it
5m 2s
Doc/ has changed
2024-10-10 12:32 UTC
3.13
ja
10m 1s
Doc/ has changed
2024-10-10 12:42 UTC
3.13
ko
5m 39s
Doc/ has changed
2024-10-10 12:47 UTC
3.13
pl
3m 51s
Doc/ has changed
2024-10-10 12:51 UTC
3.13
pt-br
5m 33s
Doc/ has changed
2024-10-10 12:57 UTC
3.13
tr
6m 3s
Doc/ has changed
2024-10-10 13:03 UTC
3.13
uk
6m 0s
new translations
2024-10-10 13:09 UTC
3.13
zh-cn
1h 9m 33s
Doc/ has changed
2024-10-10 14:18 UTC
3.13
zh-tw
1h 36m 28s
Doc/ has changed
2024-10-10 15:55 UTC
3.12
en
3m 36s
Doc/ has changed
2024-10-10 15:58 UTC
3.12
es
7m 28s
Doc/ has changed
2024-10-10 16:06 UTC
3.12
fr
9m 24s
Doc/ has changed
2024-10-10 16:15 UTC
3.12
id
6m 10s
Doc/ has changed
2024-10-10 16:22 UTC
3.12
it
4m 24s
Doc/ has changed
2024-10-10 16:26 UTC
3.12
ja
9m 14s
Doc/ has changed
2024-10-10 16:35 UTC
3.12
ko
4m 43s
Doc/ has changed
2024-10-10 16:40 UTC
3.12
pl
3m 10s
Doc/ has changed
2024-10-10 16:43 UTC
3.12
pt-br
5m 14s
Doc/ has changed
2024-10-10 16:48 UTC
3.12
tr
4m 49s
Doc/ has changed
2024-10-10 16:53 UTC
3.12
uk
4m 58s
new translations
2024-10-10 16:58 UTC
3.12
zh-cn
1h 11m 51s
Doc/ has changed
2024-10-10 18:10 UTC
3.12
zh-tw
1h 24m 36s
Doc/ has changed
2024-10-10 19:41 UTC
--FULL-
-BUILD--
11h 25m 48s
-----------
2024-10-10 20:16 UTC
3.14
en
3m 15s
Doc/ has changed
2024-10-10 20:19 UTC
3.14
es
8m 7s
Doc/ has changed
2024-10-10 20:27 UTC
3.14
fr
9m 35s
Doc/ has changed
2024-10-10 20:37 UTC
3.14
id
6m 22s
Doc/ has changed
2024-10-10 20:43 UTC
3.14
it
3m 44s
Doc/ has changed
2024-10-10 20:47 UTC
3.14
ja
8m 4s
Doc/ has changed
2024-10-10 20:55 UTC
3.14
ko
5m 33s
Doc/ has changed
2024-10-10 21:00 UTC
3.14
pl
3m 32s
Doc/ has changed
2024-10-10 21:04 UTC
3.14
pt-br
5m 39s
Doc/ has changed
2024-10-10 21:10 UTC
3.14
tr
4m 30s
Doc/ has changed
2024-10-10 21:14 UTC
3.14
uk
6m 19s
Doc/ has changed
2024-10-10 21:20 UTC
3.14
zh-cn
7m 1s
Doc/ has changed
2024-10-10 21:27 UTC
3.14
zh-tw
5m 41s
Doc/ has changed
2024-10-10 21:33 UTC
3.13
en
3m 38s
Doc/ has changed
2024-10-10 21:37 UTC
3.13
es
In progress...
...
Reacted by James Addison and Maciej Olko
Reacted by W. H. Wang
Reacted by W. H. Wang, Hugo van Kemenade and Maciej Olko
There reamain improvements to be made (e.g. speeding up or replacing Jieba), but the duration of the Chinese builds is no longer pathalogical. Thank you all for your support in improving this.
Much appreciated @AA-Turner! Sphinx 8.1 is confirmed to reduce most local build time too.
We've been suffering from this issue for too long. This patch is the savior!
Activity
AA-Turner commentedon Oct 3, 2024
The following is a heavily trimmed log for today's
zh-TWbuild:The full
reading sourcesphase takes less than two minutes, roughly as expected.The writing phase starts at 09:26:11 and ends at 10:47:11, taking 1h21m.
Looking at the duration of each chunk in detail:
All of these are taking too long, but the "library/wsgiref .. tutorial/interactive" chunk is the clear outlier at 40 minutes.
log for zh-TW
log for en (baseline)
log for es (reference translation)
rffontenelle commentedon Oct 3, 2024
Not much a contribution, but just to mention that these build times are far from e.g. Sphinx's own translated docs build. See sphinx-zh-cn (6 minutes or less) and sphinx-zh-tw (3 minutes or less)
rffontenelle commentedon Oct 3, 2024
zh_CN team seems to be caching the build to reduce time to ~2 min in their GitHub Actions runs (example). They use actions/cache/restore, build docs, and then actions/cache/save.
AA-Turner commentedon Oct 3, 2024
We need to rebuild from scratch (
-Ea) each time indocsbuild, so we can't use caching.A
jayaddison commentedon Oct 8, 2024
@AA-Turner is it possible to produce a list of the timestamps on the written files to narrow in a bit further than
library/wsgiref .. tutorial/interactiveto identify elapsed-time outliers?AA-Turner commentedon Oct 9, 2024
From the latest run:
Recursive
statof every file in the output folder (I've removed_sourcesetc):hugovk commentedon Oct 9, 2024
Highlighting some of the larger time gaps. One is a huge file, many are small, so perhaps these time gaps are misleading.
~22 minutes for
interactive.htmlhttps://docs.python.org/zh-cn/3.14/tutorial/interactive.html:~18 minutes for
changelog.html. Perhaps not surprising as this is a huge file. The html is 5.2M in English builds. It's also untranslated except for the header https://docs.python.org/zh-cn/3.14/whatsnew/changelog.html~9 minutes https://docs.python.org/zh-cn/3.14/library/winsound.html:
~8 minutes https://docs.python.org/zh-cn/3.14/library/textwrap.html:
~7 minutes https://docs.python.org/zh-cn/3.14/library/readline.html:
~5 minutes https://docs.python.org/zh-cn/3.14/library/math.html:
~5 minutes https://docs.python.org/zh-cn/3.14/library/grp.html:
mattwang44 commentedon Oct 9, 2024
if combining the logs and the stat metrics, you'll get
I wonder what does the timestamp in
1728441249 :2024-10-09 02:34:09.701973645 +0000 ./tutorial/interactive.htmlstands for? is it HTML file creation time or last modified time?If the timestamp stands for file creation time (and I assume sphinx-build appends the content to the file after the file is created and induces the gap), those timestamps would then make sense to me.
AA-Turner commentedon Oct 10, 2024
I've had some time today to do some profiling using py-spy:
$ py-spy record --format speedscope -o speedscope.json -- python -m sphinx build -M html . build -aET -D locale_dirs=locale-zh-tw -D language=zh_TW -D gettext_compact=0This reveals that the vast majority (93%) of the build duration was spent in
SearchChinese.stem. After playing around withPyStemmer, it turns out there's a much more mundane explanation.SearchChinese.latin_termsis a collection of latin terms that we might want to avoid stemming. The list survives for the duration of the build and grows to be around 53,700 elements long.SearchChinese.steminternally usesword in self.latin_termsto check membership, and hence we get appalling performance as list membership testing isWith sphinx-doc/sphinx#12995,
IndexBuilder.feed()'only' takes 24% of build duration. The slowness is almost entirely due tojieba, as on a build without it installed the method takes 1.3%..feed()duration@mattwang44 -- do you know of any better Chinese segmenters than Jieba? It hasn't been released for four years, and is quite slow.
A
AA-Turner commentedon Oct 10, 2024
python/cpython#125264 looks to use PyStemmer more generally.
A
mattwang44 commentedon Oct 10, 2024
I'm not an expert but I believe Jieba still dominates this domain.
I know two packages that are tailored for zh_TW:
For zh_CN, there's a benchmark repo shows that https://github.com/tsroten/pynlpir is slightly faster than jieba.
I wonder what role does the tokenizer play in the Sphinx? Does it affect the performance of text searching (from the search bar on the doc)?
AA-Turner commentedon Oct 10, 2024
I think without it the search is worse (original PR sphinx-doc/sphinx#2170). You could try building a copy of the zh-TW translation with and without Jieba installed and see if the search results for a chinese term are meaningfully different?
A
AA-Turner commentedon Oct 10, 2024
Latest times below. Prior to Sphinx 8.1, zh-TW took 1h 28m 16s. Now it takes 5m 41s, which is a pretty decent improvement (~15.5x). Estimated time for a full rebuild loop is now
60180 minutes, I'll keep an eye on it.A
Build times (HTML only)
AA-Turner commentedon Oct 11, 2024
There reamain improvements to be made (e.g. speeding up or replacing Jieba), but the duration of the Chinese builds is no longer pathalogical. Thank you all for your support in improving this.
A
Build times (HTML only; Chinese)
mattwang44 commentedon Oct 11, 2024
Much appreciated @AA-Turner! Sphinx 8.1 is confirmed to reduce most local build time too.
We've been suffering from this issue for too long. This patch is the savior!