diff options
| author | Paul Eggert | 2025-07-20 13:40:20 -0700 |
|---|---|---|
| committer | Paul Eggert | 2025-07-21 16:23:18 -0700 |
| commit | a8e46f11a89145390ee681e2dd14fbe6ab79b7f0 (patch) | |
| tree | 0470d8b72d73501224fce2071a184bce09db07c9 /src | |
| parent | 27e0f0f79b9c97796fc89fedf3c05517532f0475 (diff) | |
| download | emacs-a8e46f11a89145390ee681e2dd14fbe6ab79b7f0.tar.gz emacs-a8e46f11a89145390ee681e2dd14fbe6ab79b7f0.zip | |
insert-file-contents read size increase
This increases the max read size from 0.25 to 1 MiB, which is a
bit better for Emacs in my measurements. The old value was taken
from coreutils, but was for a different purpose.
* src/fileio.c (INSERT_READ_SIZE_MAX): New constant, replacing
IO_BUFSIZE. All uses changed.
(Finsert_file_contents): Do not use a read buffer that is larger
than INSERT_READ_SIZE_MAX.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/fileio.c b/src/fileio.c index 76e5e56190e..93ca8508ced 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -4048,10 +4048,6 @@ xlseek (emacs_fd fd, off_t pos, Lisp_Object filename) | |||
| 4048 | return pos; | 4048 | return pos; |
| 4049 | } | 4049 | } |
| 4050 | 4050 | ||
| 4051 | /* A good blocksize to minimize system call overhead across most systems. | ||
| 4052 | Taken from coreutils/src/ioblksize.h as of July 2025. */ | ||
| 4053 | enum { IO_BUFSIZE = 256 * 1024 }; | ||
| 4054 | |||
| 4055 | /* FIXME: insert-file-contents should be split with the top-level moved to | 4051 | /* FIXME: insert-file-contents should be split with the top-level moved to |
| 4056 | Elisp and only the core kept in C. */ | 4052 | Elisp and only the core kept in C. */ |
| 4057 | 4053 | ||
| @@ -4096,6 +4092,14 @@ by calling `format-decode', which see. */) | |||
| 4096 | (Lisp_Object filename, Lisp_Object visit, Lisp_Object beg, Lisp_Object end, | 4092 | (Lisp_Object filename, Lisp_Object visit, Lisp_Object beg, Lisp_Object end, |
| 4097 | Lisp_Object replace) | 4093 | Lisp_Object replace) |
| 4098 | { | 4094 | { |
| 4095 | /* A good read blocksize for insert-file-contents. | ||
| 4096 | It is for reading a big chunk of a file into memory, | ||
| 4097 | as opposed to coreutils IO_BUFSIZE which is for 'cat'-like stream reads. | ||
| 4098 | If too small, insert-file-contents has more syscall overhead. | ||
| 4099 | If too large, insert-file-contents might take too long respond to a quit. | ||
| 4100 | 1 MiB should be reasonable even for older, slower devices circa 2025. */ | ||
| 4101 | enum { INSERT_READ_SIZE_MAX = min (1024 * 1024, MAX_RW_COUNT) }; | ||
| 4102 | |||
| 4099 | struct timespec mtime; | 4103 | struct timespec mtime; |
| 4100 | emacs_fd fd; | 4104 | emacs_fd fd; |
| 4101 | ptrdiff_t inserted = 0; | 4105 | ptrdiff_t inserted = 0; |
| @@ -4106,7 +4110,7 @@ by calling `format-decode', which see. */) | |||
| 4106 | off_t total = 0; | 4110 | off_t total = 0; |
| 4107 | bool regular; | 4111 | bool regular; |
| 4108 | int save_errno = 0; | 4112 | int save_errno = 0; |
| 4109 | char read_buf[MAX_ALLOCA]; | 4113 | char read_buf[min (+MAX_ALLOCA, +INSERT_READ_SIZE_MAX)]; |
| 4110 | struct coding_system coding; | 4114 | struct coding_system coding; |
| 4111 | bool replace_handled = false; | 4115 | bool replace_handled = false; |
| 4112 | bool set_coding_system = false; | 4116 | bool set_coding_system = false; |
| @@ -4886,7 +4890,7 @@ by calling `format-decode', which see. */) | |||
| 4886 | else | 4890 | else |
| 4887 | { | 4891 | { |
| 4888 | buf = (char *) BEG_ADDR + PT_BYTE - BEG_BYTE + inserted; | 4892 | buf = (char *) BEG_ADDR + PT_BYTE - BEG_BYTE + inserted; |
| 4889 | bufsize = min (gap_size, IO_BUFSIZE); | 4893 | bufsize = min (gap_size, INSERT_READ_SIZE_MAX); |
| 4890 | } | 4894 | } |
| 4891 | bufsize = min (bufsize, total - inserted); | 4895 | bufsize = min (bufsize, total - inserted); |
| 4892 | 4896 | ||