[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] reducing system calls for file io
From: |
Jay Carlson |
Subject: |
[Nano-devel] reducing system calls for file io |
Date: |
Sat, 20 Apr 2002 22:36:24 -0400 |
nano performs a LOT of system calls for file IO.
For writing a standard file, there are two write() system calls per
line: one to write the body, and one to write the line terminator. Add
one more for DOS writes.
For prepending, add two system calls *per byte* in the file we're
prepending to.
This is inefficient, and affects both small systems and those with a lot
of overhead per write(). (Somebody on #handhelds.org speculated this is
why nano seemed slow on jffs2.)
nano implements its own buffered byte-by-byte reader to avoid this level
of overhead on file reads.
<goodnatured teasing on>
Because these kinds of problems affect many applications, there are
libraries that can reduce this overhead. One of them is called libc,
and the subsystem implementing this is available through #include
<stdio.h>
;-)
</teasing>
Attached to this message is a patch against CVS that switches files.c
over to using stdio for reading and writing files. In order to keep the
current tight control over open() options, file descriptors are open()ed
and then converted to FILE * via fdopen().
I should point out that I just started looking at nano tonight; there
may be subtleties in the previous behavior that I've missed. I tried
not to change the behavior much. My limited testing does show the patch
to be working.
The patch is a little verbose in that it tries to check for more failure
conditions than the previous code. It looks like there could be a lot
more error handling added to files.c, but I'm not volunteering.
Oh, and the number of write() system calls used in writing out
texinfo.tex went from around 11,000 to ~50.
I'm not subscribed to this list so please CC me on any replies.
Jay
nano-cvs-stdio.patch
Description: Binary data