make ar faster

Message ID CACcXsZi9c641-gEbCZbP0=Ni+sJKbEwW3gV6CMpT4wOjks85dg@mail.gmail.com
State Not Applicable
Headers
Series make ar faster |

Checks

Context Check Description
snail/binutils-gdb-check fail Git am fail log

Commit Message

Oleg Tolmatcev April 27, 2023, 11:35 p.m. UTC
  Hello all,

this patch makes ar faster by increasing the buffer size from 8 KB to 8 MB.

---
 bfd/archive.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
  

Comments

Nick Clifton May 3, 2023, 3:27 p.m. UTC | #1
Hi Oleg,

> this patch makes ar faster by increasing the buffer size from 8 KB to 8 MB.

Thanks for creating this patch.  I have gone ahead and applied it.
I considered changing the patch so that the buffer size was dynamic,
using a smaller buffer if the reduce_memory_overheads flag was set
in the bfd_link_info structure.  But I did not find an easy way to
get hold of that structure.

Cheers
   Nick
  
Oleg Tolmatcev May 3, 2023, 6:10 p.m. UTC | #2
Am Mi., 3. Mai 2023 um 17:27 Uhr schrieb Nick Clifton <nickc@redhat.com>:
>
> Hi Oleg,
>
> > this patch makes ar faster by increasing the buffer size from 8 KB to 8 MB.
>
> Thanks for creating this patch.  I have gone ahead and applied it.
> I considered changing the patch so that the buffer size was dynamic,
> using a smaller buffer if the reduce_memory_overheads flag was set
> in the bfd_link_info structure.  But I did not find an easy way to
> get hold of that structure.
>
> Cheers
>    Nick

Thanks again, Nick.
  

Patch

diff --git a/bfd/archive.c b/bfd/archive.c
index 4cc2f7c9..d179bcd3 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -2209,11 +2209,14 @@  _bfd_write_archive_contents (bfd *arch)
     }
     }

+  char *buffer = bfd_malloc (DEFAULT_BUFFERSIZE * 1024);
+  if (buffer == NULL)
+    return false;
+
   for (current = arch->archive_head;
        current != NULL;
        current = current->archive_next)
     {
-      char buffer[DEFAULT_BUFFERSIZE];
       bfd_size_type remaining = arelt_size (current);

       /* Write ar header.  */
@@ -2226,7 +2229,7 @@  _bfd_write_archive_contents (bfd *arch)

       while (remaining)
     {
-      size_t amt = DEFAULT_BUFFERSIZE;
+      size_t amt = DEFAULT_BUFFERSIZE * 1024;

       if (amt > remaining)
         amt = remaining;
@@ -2245,6 +2248,8 @@  _bfd_write_archive_contents (bfd *arch)
     }
     }

+  free (buffer);
+
   if (makemap && hasobjects)
     {
       /* Verify the timestamp in the archive file.  If it would not be