hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit c007a54a3e7afecb3e4a61d0b7b0720cd6bff25d
parent fb804916039bfde1628b08ea7a8bc835e7216f06
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat, 10 Apr 2021 11:05:15 -0400

os: add BUFSIZ; use for stdin, stdout, format::xml

I set this to 1MiB for now, for Linux. This is a lot bigger than musl (1
KiB) or glibc (8 KiB), but 1 MiB is not a log of memory to stick in .bss
these days, and, generally speaking, the larger the buffer is, the
better performance is. This change alone leads to a 30% increase in
format::xml performance, for instance.

Diffstat:
Mformat/xml/types.ha | 3++-
Mos/+linux/stdfd.ha | 7+++++--
2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/format/xml/types.ha b/format/xml/types.ha @@ -1,11 +1,12 @@ use encoding::utf8; use io; +use os; // Represents the state for an XML parser. export type parser = struct { orig: *io::stream, in: *io::stream, - buf: [4096]u8, + buf: [os::BUFSIZ]u8, state: state, // strio buffers: namebuf: *io::stream, diff --git a/os/+linux/stdfd.ha b/os/+linux/stdfd.ha @@ -8,15 +8,18 @@ let static_stderr_fd: fd_stream = fd_stream { ... }; let static_stdin_bufio: bufio::bufstream = bufio::bufstream { ... }; let static_stdout_bufio: bufio::bufstream = bufio::bufstream { ... }; +// The recommended buffer size for reading from disk. +export def BUFSIZ: size = 1048576; // 1 MiB + @init fn init_stdfd() void = { stdin = static_fdopen(0, "<stdin>", io::mode::READ, &static_stdin_fd); stdout = static_fdopen(1, "<stdout>", io::mode::WRITE, &static_stdout_fd); stderr = static_fdopen(2, "<stderr>", io::mode::WRITE, &static_stderr_fd); - static let stdinbuf: [4096]u8 = [0...]; + static let stdinbuf: [BUFSIZ]u8 = [0...]; stdin = bufio::static_buffered(stdin, stdinbuf, [], &static_stdin_bufio); - static let stdoutbuf: [4096]u8 = [0...]; + static let stdoutbuf: [BUFSIZ]u8 = [0...]; stdout = bufio::static_buffered(stdout, [], stdoutbuf, &static_stdout_bufio); };