[Fedora-packaging] Re: Hardlinking *.pyc and *.pyo

Axel Thimm Axel.Thimm at ATrpms.net
Tue Apr 3 12:01:06 UTC 2007


On Tue, Apr 03, 2007 at 01:42:24PM +0300, Ville Skyttä wrote:
> Related to recent space saving discussions, I came across PLD's
> rpm-build-macros package recently, and found that they hardlink
> identical *.pyc and *.pyo.  In a lot of cases, they're the same,
> and there's some potential for saving some MB "for free",
> on my FC6 x86_64 box:
> 
> $ /usr/sbin/hardlink -ncv /usr/lib*/python2.4 2>&1 | tail -n 1
> Would save 11116544

I get more than twice as much on a typical FC6/x86_64 system:
27275264. That's 26 MB on 166MB total, e.g. saving 16%.

# du -sc /usr/lib*/python2.4| tail -n 1
170200  total

On another system I get 21MB of 144MB total, e.g about 15%.

> The PLD implementation looks like this:
> 
> # Hardlink binary identical .pyc and .pyo files
> # (idea by glen <at> pld-linux <dot> org)
> %__spec_install_post_py_hardlink {\
> %{!?no_install_post_py_hardlink: __spec_install_post_py_hardlink() { \
> [ ! -d "$RPM_BUILD_ROOT" ] || find "$RPM_BUILD_ROOT" -name '*.pyc' | while read a; do \
>         b="$(echo $a|sed -e 's/.pyc$/.pyo/')"; \
>         if cmp -s "$a" "$b"; then \
>                 ln -f "$a" "$b"; \
>         fi; \
> done \
> }; __spec_install_post_py_hardlink } }
> 
> The use of "cmp" would require diffutils installed.  Or the above
> could be converted to use hardlink instead (which would have to be made
> sure to be around) or maybe sha1sum (in coreutils, pretty much always
> around in buildroots).
> 
> I suppose something like the above could be easily added to
> redhat-rpm-config or rpm, eg. embedded in brp-python-bytecompile
> or run after it in %__os_install_post.

brp-python-bytecompile sounds like the best spot since the pyc/pyos
are created there. Maybe we should ship an improved
brp-python-bytecompile in redhat-rpm-config while lobbying rpm
upstream to adopt it?

> Worth it?  Other comments?

A 15% space gain (under python) w/o any drawbacks? Always worth it. :)
-- 
Axel.Thimm at ATrpms.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/fedora-packaging/attachments/20070403/2a84b414/attachment.sig>


More information about the Fedora-packaging mailing list