aboutsummaryrefslogtreecommitdiffstats
path: root/cache.c
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2026-05-21 15:11:10 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2026-09-18 13:48:51 +0200
commit599e3df55ff0ce7387172c16cba269d545019ed3 (patch)
tree76f53bd8e99f3a676a31f5484080c3775bd97ccd /cache.c
parentbd308735b3cfd40a57b20723a6e6862bf8303dc0 (diff)
downloadcgit-599e3df55ff0ce7387172c16cba269d545019ed3.tar.gz
cgit-599e3df55ff0ce7387172c16cba269d545019ed3.tar.bz2
cgit-599e3df55ff0ce7387172c16cba269d545019ed3.zip
html: use buffered stdio
Our generation of HTML triggers many small write(2) syscalls which is inefficient. Time output on a horrible query against my git.git mirror shows significant performance improvement: QUERY_STRING='id=2b93bfac0f5bcabbf60f174f4e7bfa9e318e64d5&id2=d6da71a9d16b8cf27f9d8f90692d3625c849cbc8' PATH_INFO=/mirrors/git.git/diff export QUERY_STRING PATH_INFO time ./cgit >/dev/null Before: real 0m1.585s user 0m0.904s sys 0m0.658s After: real 0m0.750s user 0m0.666s sys 0m0.076s Signed-off-by: Eric Wong <e@80x24.org> Signed-off-by: Alyssa Ross <hi@alyssa.is> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'cache.c')
-rw-r--r--cache.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/cache.c b/cache.c
index e70af13..13cceac 100644
--- a/cache.c
+++ b/cache.c
@@ -272,6 +272,13 @@ static int process_slot(struct cache_slot *slot)
{
int err;
+ /*
+ * Make sure any buffered data is flushed before we redirect,
+ * do sendfile(2) or write(2)
+ */
+ if (fflush(stdout))
+ return errno;
+
err = open_slot(slot);
if (!err && slot->match) {
if (is_expired(slot)) {