chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] printf and overhead


From: Peter Bex
Subject: [Chicken-hackers] printf and overhead
Date: Mon, 4 Feb 2008 01:16:32 +0100
User-agent: Mutt/1.4.2.3i

Hello chickeners,

I just finished the 9p egg and am currently writing a wmiirc egg.
In doing so, I found a peculiar problem.  When writing commands to
wmii's /tag/sel/ctl, it kept giving me an error that it didn't
understand the commands I was writing to it.

Now, I write to wmii's 9p server using something equivalent to
(9p:with-output-to-file con "/tag/sel/ctl" (lambda () (printf "select ~A" 
"up")))
It turns out that printf writes one character at a time, which my custom
output port dutily writes out one 9p protocol "write" message at a time.

For wmii to understand these commands, they have to be written all at
once, in one big write command.  So if you write it in two bursts, it
sees it as two separate commands.

Besides this not working in the particular case of wmii (I can work
around that using sprintf and display in the wmii client code),
this is potentially very inefficient, especially considering custom
output ports like the 9p output ports, but with more overhead per write.
If you have, say, 10 bytes of protocol overhead per 1 byte of actual
content, the overhead will kill you in the long run.

So my suggestion is to swap around fprintf and sprintf, such that sprintf
contains the string formatting implementation and fprintf just calls
sprintf followed by display.  That way the entire string is output in one
big burst instead of one char at a time.

Alternatively, if this would be too much overhead in the typical case
of writing to a terminal, if it's possible to detect that the port is a
custom one, follow the route of using sprintf first in that case and the
current behaviour in other cases.

Of course one could implement line buffering whenever creating custom
output ports, but surely that's not desirable in many cases.  There are
conceivably many other situations where the semantics of the device or
protocol you're writing to differ between sending many messages and single
messages.

What do you guys think?

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
                                                        -- Donald Knuth

Attachment: pgpRXYgMibkcE.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]