Browse Source

Use a hardcoded buffer size of 4096 to fix performance

The code uses memmove() to move parts of the buffer to the
front when the buffer is only partially read. By simply
reading one page at a time, the maximum size of bytes that
must be moved has a hard limit, and performance improves:

In one test case, consisting of a 430 MB Contents file,
and a 75K PDiff, applying the PDiff previously took about
48 seconds and now completes in 2 seconds.

Further speed up can be achieved by buffering writes, they
account for about 60% of the run-time now.
Julian Andres Klode 10 years ago
parent
commit
0b29c72bdf
1 changed files with 2 additions and 4 deletions
  1. 2 4
      apt-pkg/contrib/fileutl.cc

+ 2 - 4
apt-pkg/contrib/fileutl.cc

@@ -922,7 +922,7 @@ bool ChangeOwnerAndPermissionOfFile(char const * const requester, char const * c
 class APT_HIDDEN FileFdPrivate {							/*{{{*/
 class APT_HIDDEN FileFdPrivate {							/*{{{*/
 protected:
 protected:
    FileFd * const filefd;
    FileFd * const filefd;
-   size_t buffersize_max = 0;
+   const size_t buffersize_max = 4096;
    std::unique_ptr<char[]> buffer;
    std::unique_ptr<char[]> buffer;
    unsigned long long buffersize = 0;
    unsigned long long buffersize = 0;
 public:
 public:
@@ -984,8 +984,7 @@ public:
 	 {
 	 {
 	    if (buffer.get() == nullptr)
 	    if (buffer.get() == nullptr)
 	    {
 	    {
-	       buffer.reset(new char[Size]);
-	       buffersize_max = Size;
+	       buffer.reset(new char[buffersize_max]);
 	    }
 	    }
 	    unsigned long long actualread = 0;
 	    unsigned long long actualread = 0;
 	    if (filefd->Read(buffer.get(), buffersize_max, &actualread) == false)
 	    if (filefd->Read(buffer.get(), buffersize_max, &actualread) == false)
@@ -994,7 +993,6 @@ public:
 	    if (buffersize == 0)
 	    if (buffersize == 0)
 	    {
 	    {
 	       buffer.reset(nullptr);
 	       buffer.reset(nullptr);
-	       buffersize_max = 0;
 	       if (To == InitialTo)
 	       if (To == InitialTo)
 		  return nullptr;
 		  return nullptr;
 	       break;
 	       break;