]> granicus.if.org Git - neomutt/commitdiff
Use unlocked libc IO everywhere.
authorDavid Wilson <dw@botanicus.net>
Tue, 22 Oct 2013 18:34:57 +0000 (11:34 -0700)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 02:32:55 +0000 (03:32 +0100)
Since mutt does not use threads, there is no reason it should use the
locked variants of the FILE* IO functions. This checks if the unlocked
functions are available, and if so enables them globally via mutt.h.

Cuts load time for a 56k message, 1.8GB /var/mail mailbox from 14
seconds to ~6 seconds, since we avoid acquiring and releasing a mutex
for every character of input read.

Before: 0m14.376s

    74.98%          mutt  libc-2.18.so        [.] _IO_getc
    11.87%          mutt  mutt                [.] mbox_parse_mailbox
     0.94%          mutt  [kernel.kallsyms]   [k] copy_user_generic_string
     0.83%          mutt  libc-2.18.so        [.] __strchr_sse2
     0.53%          mutt  libc-2.18.so        [.] __memcpy_sse2
     0.44%          mutt  libc-2.18.so        [.] _int_malloc

After: 6 seconds

    68.92%     mutt  mutt                  [.] mbox_parse_mailbox
     2.25%     mutt  [kernel.kallsyms]     [k] copy_user_generic_string
     1.73%     mutt  libc-2.18.so          [.] __strchr_sse2
     1.24%     mutt  libc-2.18.so          [.] __memcpy_sse2
     1.17%     mutt  libc-2.18.so          [.] _int_malloc
     0.87%     mutt  libc-2.18.so          [.] __strspn_sse42

configure.ac
mutt.h

index c84fcb714a7d06490105363e1d70b3da20ed991f..811a2439e9e55079732f7ae2c726033b9fa448df 100644 (file)
@@ -313,6 +313,7 @@ AC_CHECK_HEADERS(sys/time.h sys/resource.h)
 AC_CHECK_HEADERS(unix.h)
 
 AC_CHECK_FUNCS(setrlimit getsid)
+AC_CHECK_FUNCS(fgets_unlocked fgetc_unlocked)
 
 AC_MSG_CHECKING(for sig_atomic_t in signal.h)
 AC_EGREP_HEADER(sig_atomic_t,signal.h,
diff --git a/mutt.h b/mutt.h
index de26fd84226daf057ddcc9841c8d0da4828956c4..0b62b73e88e6dad0432ccdd3761497dbb65072d4 100644 (file)
--- a/mutt.h
+++ b/mutt.h
 # define MB_LEN_MAX 16
 #endif
 
+#ifdef HAVE_FGETS_UNLOCKED
+# define fgets fgets_unlocked
+#endif
+
+#ifdef HAVE_FGETC_UNLOCKED
+# define fgetc fgetc_unlocked
+#endif
+
 /* nifty trick I stole from ELM 2.5alpha. */
 #ifdef MAIN_C
 #define WHERE