speechd-discuss
[Top][All Lists]
Advanced

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

line buffering vs no buffering


From: David Turner
Subject: line buffering vs no buffering
Date: Fri, 2 Jun 2023 13:39:21 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0

[x-post from github https://github.com/brailcom/speechd/issues/833]

I'm not subscribed, so please CC-me.

Steps to reproduce

As I noted in my patch[1], I have about 15,000 voices (I don't know why; I think I've just got default Debian). So spd_list_synthesis_voices is slow, taking (after that PR) about 0.5s. I can reduce that to 0.35s with:

diff --git a/src/api/c/libspeechd.c b/src/api/c/libspeechd.c
index 2ef3b9ea..c7b54feb 100644
--- a/src/api/c/libspeechd.c
+++ b/src/api/c/libspeechd.c
@@ -543,7 +543,7 @@ SPDConnection *spd_open2(const char *client_name, const char *connection_name,
        if (!connection->stream)
                SPD_FATAL("Can't create a stream for socket, fdopen() failed.");
        /* Switch to line buffering mode */
-       ret = setvbuf(connection->stream, NULL, _IONBF, SPD_REPLY_BUF_SIZE);
+       ret = setvbuf(connection->stream, NULL, _IOLBF, SPD_REPLY_BUF_SIZE);
        if (ret)
                SPD_FATAL("Can't set buffering, setvbuf failed.");

Note that this was the original code, before ec25ad9 (in 2005). Notice also the comment claiming this sets line buffering mode: while the code was changed, the comment was not.

Obtained behavior

spd-say -L reads one character at a time, leading to over 400k read syscalls.

Expected behavior

Looks like 208 read syscalls afterwards (although some may be from other sources; at any rate, client i/o is no longer the bottleneck).

Note that

speechd/src/server/module.c

Line 502 in 95e7a9c

ret = setvbuf(module->stream_out, NULL, _IONBF, 4096);
has the same problem (including bogus comment), dating from 541f955 (committed a few minutes after ec25ad9)

I didn't try changing that to see if it would further improve perf, since that seemed more complicated to test (since I am already running my distro's version of speech-dispatcher). But I bet it would.

Distribution

Debian

Version of Speech-dispatcher

My comments are as-of 95e7a9c

(See https://github.com/godotengine/godot/issues/77754 for one consequence of this performance -- it's somewhat fixed, but the code still has to be run once, leading to a one-time slowdown).


[1] https://github.com/brailcom/speechd/pull/832 -- if you would prefer patches to go to this list, please let me know and I can `git send-email` it over. 


reply via email to

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