#31692: compilemessages needlessly runs msgfmt on unchanged .po files
-------------------------------------+-------------------------------------
               Reporter:  cederlys   |          Owner:  nobody
                   Type:             |         Status:  new
  Cleanup/optimization               |
              Component:  Core       |        Version:  master
  (Management commands)              |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31692>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.bae426a4462cb04cc2f506c3b6aaeaaa%40djangoproject.com.

Reply via email to