8000 blurb: don't overwrite output when not necessary by dmerejkowsky · Pull Request #403 · python/core-workflow · GitHub
[go: up one dir, main page]

Skip to content

blurb: don't overwrite output when not necessary #403

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

Merged
merged 2 commits into from
May 26, 2021

Conversation

dmerejkowsky
Copy link
Contributor

This speeds up the build of the Python documentation
quite a bit, since the NEWS file is huge and causes
sphinx to rebuild its doctree each time the doc
is built, regardless of the other changes

@dmerejkowsky
Copy link
Contributor Author

Poke @JulienPalard

@dmerejkowsky
Copy link
Contributor Author

Example of speed up gained from the patch

Without this patch, building the French translation after changing one .po takes 30 seconds

With this patch, it only takes 12.

@JulienPalard
Copy link
Member
JulienPalard commented May 12, 2021

How did you tested this?

I'm testing it using:

$ hyperfine '../../core-workflow/blurb/blurb.py merge -f build/NEWS'

and I'm getting similar results with master vs your branch:

Time (mean ± σ):      2.767 s ±  0.300 s    [User: 2.743 s, System: 0.021 s]

vs

Time (mean ± σ):      2.683 s ±  0.288 s    [User: 2.662 s, System: 0.020 s]

@JulienPalard
Copy link
Member

(You can rebase on top of master if you want the CI to have a chance to pass)

@encukou
Copy link
Member
encukou commented May 12, 2021

I'm getting similar results with master vs your branch

The speedup comes later. With this change, blurb won't update the file unnecessarily, which means Sphinx will then use a cache instead of parsing it again.

@dmerejkowsky
Copy link
Contributor Author

Thanks @encukou, that's a perfect description of what I was trying to achieve :)

@dmerejkowsky
Copy link
Contributor Author

Rebased but I need an approval for the workflow to run. (BTW, thanks for the CI fix)

Copy link
Member
@encukou encukou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good and I get the same output as with the current blurb.
This does load the entire NEWS file into memory twice, but I don't think that's an issue nowadays.

@encukou encukou changed the title Speedup blurb blurb: don't overwrite output when not necessary May 13, 2021
@JulienPalard
Copy link
Member

The speedup comes later. With this change, blurb won't update the file unnecessarily,

So why hyperfine did not catched up the speedup? As hyperfine runned blurb multiple times, if succequent runs are faster, I should have spoted the difference?

Also got this today while trying:

$ ../../core-workflow/blurb/blurb.py merge build/NEWS
Traceback (most recent call last):
  File "/home/mdk/clones/python/cpython/Doc/../../core-workflow/blurb/blurb.py", line 1705, in <module>
    main()
  File "/home/mdk/clones/python/cpython/Doc/../../core-workflow/blurb/blurb.py", line 1665, in main
    sys.exit(fn(*filtered_args, **kwargs))
  File "/home/mdk/clones/python/cpython/Doc/../../core-workflow/blurb/blurb.py", line 1068, in merge
    write_news(output, versions=versions)
  File "/home/mdk/clones/python/cpython/Doc/../../core-workflow/blurb/blurb.py", line 1138, in write_news
    with open(output, "r", encoding="utf-8") as file:
FileNotFoundError: [Errno 2] No such file or directory: '/home/mdk/clones/python/cpython/Doc/build/NEWS'

@dmerejkowsky
Copy link
Contributor Author

So why hyperfine did not catched up the speedup

No clue. Measuring performance is hard ... But as stated above, the goal is to speed up the sphinx build when blurb is called, not blurb itself.

Also got this today while trying [...]

I used this

cd cpython/Doc
make BLURB=/mnt/data/dmerej/src/python-core-workflow/blurb/blurb.py  html

@JulienPalard
Copy link
Member

I'm testing with blurb -f merge because that's what the doc's Makefile is using.

@JulienPalard
Copy link
Member

But as stated above, the goal is to speed up the sphinx build when blurb is called, not blurb itself.

Oh you mean to avoid cache thinking the file has changed by not touching it? Got it now \o/ I had the feeling I was not understanding something ... I was not understanding something!

Can you please just double check the exception on merge? I don't want the next docs build to fail :p

@dmerejkowsky
Copy link
Contributor Author

Can you please just double check the exception on merge? I don't want the next docs build to fail :p

Me neither - but I can't reproduce the exception. This is weird. If you're afraid of breakage, we could push a beta version of blurb on pypi and check nothing breaks, no ?

@JulienPalard
Copy link
Member
JulienPalard commented May 13, 2021

I'd look at it on my machine, as I can reproduce it, but not right now, I'm attending the trainers summit... I only have half my brain available :D Enough to run hyperfine, not enough to read the code :D

@JulienPalard
Copy link
Member

OK my reproducer is:

rm -f build/NEWS; ../../core-workflow/blurb/blurb.py merge -f build/NEWS

which make sense: if the file does not exists, you can't compare it. what about:

new_contents = buff.getvalue()
try:
    previous_contents = Path(output).read_text(encoding="UTF-8")
except (FileNotFoundError, UnicodeError):
    previous_contents = None
if new_contents != previous_contents:
    Path(output).write_text(new_contents, encoding="UTF-8")
else:
    builtins.print(output, "is already up to date")

@dmerejkowsky
Copy link
Contributor Author

Yup, that sounds better :)

This speeds up doc generation.

With this change, blurb won't update the NEWS file unnecessarily, which
means Sphinx will then use a cache instead of parsing it again.
@JulienPalard JulienPalard merged commit 96735b6 into python:master May 26, 2021
@JulienPalard
Copy link
Member

Thanks a lot @dmerejkowsky!

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

Successfully merging this pull request may close these issues.

4 participants
0