Howdy guys. Sorry for the crosspost. Patch to speed up taglib.

Manuel Amador (Rudd-O) rudd-o at rudd-o.com
Fri Oct 5 17:32:12 CEST 2007


Here's a patch.  Hope it's useful.

I dunno how to make KMail not linewrap, so I'm attaching it and pasting it as 
well.

This patch implements on posix systems the fadvise system call that makes the 
system not readahead mp3 while scanning for tags.  It's absurd to introduce 
readahead to a problem that entails reading two or three 64 K pages at most.  
Less I/O is good. right?

This has also been posted to:
http://rudd-o.com/archives/2007/10/05/speeding-amarok-up/

Discuss.

-------------------------------------------------


rudd-o at karen:~/Projects/amaroK/newamarok/kdesupport/taglib$ svn diff
Index: taglib/toolkit/tfile.cpp
===================================================================
--- taglib/toolkit/tfile.cpp    (revisión: 721576)
+++ taglib/toolkit/tfile.cpp    (copia de trabajo)
@@ -41,6 +41,10 @@
 # define W_OK 2
 #endif

+#ifdef _XOPEN_SOURCE
+#include <fcntl.h>
+#endif
+
 using namespace TagLib;

 class File::FilePrivate
@@ -73,6 +77,7 @@

 File::File(const char *file)
 {
+  int fadvise_retvalue = 0;
   d = new FilePrivate(::strdup(file));

   // First try with read/write mode, if that fails, fall back to read only.
@@ -87,6 +92,15 @@

   if(!d->file)
     debug("Could not open file " + String(file));
+
+#ifdef _XOPEN_SOURCE
+  /* Rudd-O: we don't want the kernel to cache this file descriptor or 
perform any readahead -- but only if no one else opens the file.  see 
posix_fadvise(2) */
+  if(d->file) {
+    fadvise_retvalue = posix_fadvise(fileno(d->file),0,0,POSIX_FADV_RANDOM);
+    if (fadvise_retvalue != 0)
+      debug("Could not tell the kernel to not cache the file " + 
String(file));
+  }
+#endif
 }

 File::~File()





-------------------------------------------------


-- 

	Manuel Amador (Rudd-O) <rudd-o at rudd-o.com>
	Rudd-O.com - http://rudd-o.com/
	GPG key ID 0xC8D28B92 at http://wwwkeys.pgp.net/

Now playing, courtesy of Amarok: Vincent Vargas feat. Kissey Asplund - Why 
talkin'
You will be honored for contributing your time and skill to a worthy cause.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: taglib arrogant speedup patch.diff
Type: text/x-diff
Size: 1062 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/taglib-devel/attachments/20071005/aa49e67d/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://mail.kde.org/pipermail/taglib-devel/attachments/20071005/aa49e67d/attachment.pgp 


More information about the taglib-devel mailing list