#31692 closed Cleanup/optimization (fixed)
compilemessages needlessly runs msgfmt on unchanged .po files
Reported by: | Per Cederqvist | Owned by: | Claude Paroz |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have a project where running django-admin compilemessages
takes 1.75 seconds. Running it again, when all the .mo
files already exists and are up-to-date, also takes 1.75 seconds.
I propose that compilemessages.py
is changed so that it only invokes msgfmt
when it would do anything useful. This can be implemented by checking the mtime of the .po
file and the corresponding .mo
file. (If statting the .mo
file fails, treat that as if the mtime was 0.) Only submit the command to the executor
if the mtime of the .po
file is greater than that of the .mo
file. In effect: don't do anything if the .mo
file is newer than the .po
file.
There is one issue with this: the way the code currently uses the is_writable
function. Since it modifies the mtime of the .mo
file, you would have to perform the stat of the .mo
file before you check if it is writable. (Or, you could just remove the is_writable
function and its use. That feature is, in my opinion, of dubious value, and it doesn't appear to be documented.)
After I made the changes above, the runtime in the common case where nothing needs to be done was reduced from 1.75 seconds to 0.2 seconds.
(Unfortunately, I doubt that I will be able to get a Corporate Contributor License Agreement signed, so I can unfortunately not contribute my change.)
1.75 seconds may not be much, but when a CI system does it repeatedly, it adds up.
Change History (6)
comment:1 by , 5 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Proposal makes sense.
About the CLA, I don't remember one time where we refused a contribution because of that (should be time to drop it?).