From: Paul Eggert Date: Sun, 13 Jul 2025 20:33:27 +0000 (-0700) Subject: Speed up insert-file-contents reads X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0d2c9b3a23373cd02134f8a1d400cd28ac277eeb;p=emacs.git Speed up insert-file-contents reads This change makes insert-file-contents-literally 30% faster on my platform, when inserting xdisp.c. * src/fileio.c (READ_BUF_SIZE): Remove, replacing with ... (IO_BUFSIZE): ... this new constant from Coreutils. All uses of READ_BUF_SIZE changed to either MAX_ALLOCA or IO_BUFSIZE. (cherry picked from commit 5bce6753e24d04ea3e4715fab53cc65c1b4ee8d7) --- diff --git a/src/fileio.c b/src/fileio.c index 075b9c590c8..8e1ac42723d 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -3836,8 +3836,6 @@ For existing files, this compares their last-modified times. */) ? Qt : Qnil); } -enum { READ_BUF_SIZE = MAX_ALLOCA }; - /* This function is called after Lisp functions to decide a coding system are called, or when they cause an error. Before they are called, the current buffer is set unibyte and it contains only a @@ -4028,6 +4026,10 @@ maybe_move_gap (struct buffer *b) } } +/* A good blocksize to minimize system call overhead across most systems. + Taken from coreutils/src/ioblksize.h as of July 2025. */ +enum { IO_BUFSIZE = 256 * 1024 }; + /* FIXME: insert-file-contents should be split with the top-level moved to Elisp and only the core kept in C. */ @@ -4082,7 +4084,7 @@ by calling `format-decode', which see. */) off_t total = 0; bool regular; int save_errno = 0; - char read_buf[READ_BUF_SIZE]; + char read_buf[MAX_ALLOCA]; struct coding_system coding; bool replace_handled = false; bool set_coding_system = false; @@ -4861,7 +4863,7 @@ by calling `format-decode', which see. */) else { buf = (char *) BEG_ADDR + PT_BYTE - BEG_BYTE + inserted; - bufsize = min (min (gap_size, total - inserted), READ_BUF_SIZE); + bufsize = min (min (gap_size, total - inserted), IO_BUFSIZE); } if (!seekable && end_offset == TYPE_MAXIMUM (off_t))