libtool-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

make libtool faster v1


From: Ralf Wildenhues
Subject: make libtool faster v1
Date: Mon, 29 Nov 2004 12:10:30 +0100
User-agent: Mutt/1.4.1i

[ Please skip to below *** if you don't want care about the boilerplate
stuff. ]

People complain about libtool being slow.  People even consider to and
do turn away from using the autotools for the sole reason of them being
slow.  It's mainly the developers that get annoyed at having to wait
forever for `libtool --mode=link' to sort its business out after each
little code change.

As much as I don't think premature optimization is good, and I would
agree on valuing maintainability and even more portability over
efficiency, we should not forget about this completely.

To be specific: There are packages out there that use libtool to link
more than 800 .lo files into a libtool library[1].  It's not uncommon
to wait for a minute for libtool to sort everything out, and then three
more seconds for ld to link everything.  With branch-2-0, things will
get worse, unfortunately (at least as of now).  

So I did simple checks, stuff far less work than rewriting in C.
On the system I checked, the quadratic scaling of loops like this:
  for arg
  do
    # ...
    foo_command="$foo_command arg"
  done

is still not the bottleneck with around 800 .lo files, but the forks
that are done once per .lo file.

***

So, to get to my point:  Would the others accept speedup patches?
Here's a real simple one, speeds up `libtool --mode=link' by about 20%
on a modern linux in example case from above.  (The equivalent change on
branch-1-5 makes for a speedup by more than 30%).  For now, it has a
drawback: it depends on the user not using stdin (e.g., in conjunction
with a `-' argument somewhere).  Do we support this mode?  If so, we
need to check if we can dup the stdin descriptor somewhere safe.

The patch should be portable AFAIK, but please double-check.  Still, I
didn't want to have to trust shells to cope with `read' getting fed
arbitrary junk, so I made another function func_lalib_unsafe_p which is
only to be called if we bail out anyway in case the answer is no.

The patch below is against HEAD, though I'd really like to backport to
branch-2-0 and branch-1-5 as well.

Regards,
Ralf

[1] I happen to be a user of more than one of those.

2004-11-29  Ralf Wildenhues <address@hidden>

        * config/ltmain.m4sh (func_lalib_p): Update function
        description. (func_lalib_unsafe_p): New function with same
        functionality but written without forks; this function is safe
        to use for cases where the argument either does not exist or
        is required to be a lalib for correct operation.
        * (func_mode_execute, func_mode_install, func_mode_link):
        Use func_lalib_unsafe_p where appropriate.
        * (func_mode_execute): For the program wrapper, use
        func_ltwrapper_p instead of func_lalib_p.



Index: config/ltmain.m4sh
===================================================================
RCS file: /cvsroot/libtool/libtool/config/ltmain.m4sh,v
retrieving revision 1.25
diff -u -r1.25 ltmain.m4sh
--- config/ltmain.m4sh  22 Nov 2004 22:36:16 -0000      1.25
+++ config/ltmain.m4sh  29 Nov 2004 07:34:18 -0000
@@ -574,15 +574,34 @@
 
 
 # func_lalib_p file
-# True iff FILE is a libtool `.la' library.
+# True iff FILE is a libtool `.la' library or .lo object file.
 # This function is only a basic sanity check; it will hardly flush out
 # determined imposters.
 func_lalib_p ()
 {
     $SED -e 4q "$1" 2>/dev/null \
       | $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
 }
 
+# func_lalib_unsafe_p file
+# True iff FILE is a libtool `.la' library or .lo object file.
+# Does the same as func_lalib_p, but is intended only for checks where
+# a negative result would be fatal.  Works if file does not exist.
+func_lalib_unsafe_p ()
+{
+    lalib_p=no
+    if test -r "$1" && exec <"$1"; then
+       for lalib_p_l in 1 2 3 4
+       do
+           read lalib_p_line
+           case "$lalib_p_line" in
+               \#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
+           esac
+       done
+       exec <&-
+    fi
+    test "$lalib_p" = yes
+}
 
 # func_ltwrapper_p file
 # True iff FILE is a libtool wrapper script.
@@ -1438,7 +1457,7 @@
       case $file in
       *.la)
        # Check to see that this really is a libtool archive.
-       func_lalib_p "$file" \ ||
+       func_lalib_unsafe_p "$file" \ ||
          func_fatal_help "\`$lib' is not a valid libtool archive"
 
        # Read the libtool library.
@@ -1505,7 +1524,7 @@
       -*) ;;
       *)
        # Do a test to see if this is really a libtool program.
-       if func_lalib_p "$file"; then
+       if func_ltwrapper_p "$file"; then
          # If there is no directory component, then add one.
          case $file in
          */* | *\\*) . $file ;;
@@ -1765,7 +1784,7 @@
 
       *.la)
        # Check to see that this really is a libtool archive.
-       func_lalib_p "$file" || \
+       func_lalib_unsafe_p "$file" || \
          func_fatal_help "\`$file' is not a valid libtool archive"
 
        library_names=
@@ -2299,7 +2318,7 @@
              # A libtool-controlled object.
 
              # Check to see that this really is a libtool object.
-             if func_lalib_p "$arg"; then
+             if func_lalib_unsafe_p "$arg"; then
                pic_object=
                non_pic_object=
 
@@ -2792,7 +2811,7 @@
        # A libtool-controlled object.
 
        # Check to see that this really is a libtool object.
-       if func_lalib_p "$arg"; then
+       if func_lalib_unsafe_p "$arg"; then
          pic_object=
          non_pic_object=
 
@@ -3305,7 +3324,7 @@
        fi
 
        # Check to see that this really is a libtool archive.
-       func_lalib_p "$lib" || \
+       func_lalib_unsafe_p "$lib" || \
          func_fatal_error "\`$lib' is not a valid libtool archive"
 
        ladir=`$ECHO "X$lib" | $Xsed -e 's%/[[^/]]*$%%'`




reply via email to

[Prev in Thread] Current Thread [Next in Thread]