3 ms·
In the 1980s, Borland made up for much of the poor code generation of their C compiler by doing the runtime library all in hand-optimized assembler, including p
by WalterBright 9y ago
In the 1980s, Borland made up for much of the poor code generation of their C compiler by doing the runtime library all in hand-optimized assembler, including printf.
What I did (Datalight, Zortech) was make large disk I/O buffers. It gave huge boosts to speed, and very few people cottoned on to that :-)
It was a technique I learned from Shal Farley.
- neonate 9y agoCan you say more? How did it give huge boosts to speed?
- WalterBright 9y agoA typical buffer size for DOS was 512 bytes, the size of a floppy disk sector. I used 20K. Writing bigger chunks at a time enabled the operating system to optimize it for better throughput to the disk driver. (Fewer seeks, for example.) Fewer round trips to the operating system almost always speeds things up, too, especially if it involves a context switch. Things got even better when the switch to hard disks was underway. Hard disks had bigger sector sizes, but the buffer size sometimes remained at 512. This meant the driver had to read the sector, fold in the 512, then write it back out. Oops! Later on, demand paged virtual memory and memory caching also favored big buffers.
- sillysaurus3 9y agoIt's interesting how similar that is to the type of optimizations gamedevs do today. E.g. sub out "floppy disk sector" for GPU memory and crank up the numbers a few orders of magnitude.
- masklinn 9y agoIt's not just gamedevs. I/O buffering remains an important source of both performances and frustrations (when the I/O is buffered a bit too heavily and nothing appears in the output because in-memory buffers are still filling), and most modern languages provide buffering wrappers or even buffer file I/O by default.
- caf 9y agoHard disk sectors were 512 bytes and remained that way up until about 2010. ITYM the FAT cluster size?
- WalterBright 9y agoIf I recall correctly, disks emulated 512 byte sectors for compatibility, but actually had larger ones. But I don't have documentation on such pre-google things :-)
- baruch 9y agoDisk sectors remained 512 for a very long time, only in recent years (2010 sounds right) did they make the 4k sectors with emulation for 512 or just native 4k drives. It is true however that sequential access to hdds and floppies was always much faster than random access or even sequential in small buffers simply because the drive does not need to wait for the platter rotation to reach the right location again for each sector written but rather just write them all in one go.
- wruza 9y agoFloppy track seeking is such a pain to wait, so smartdrv.exe never left my autoexec.bat once discovered. I don’t understand how that wasn’t a default for latest DOSes.
- JdeBP 9y agoAs I recall, Borland's printf() was C code with the occasional pieces of inline assembly language; and this was the case for most of the C runtime library. There were occasional pieces actually implemented as fully fledged assembly language modules, but this was far from "all" of the runtime library.