From e146ca6bb88dc8a70a7897dcfd07940e046f7e33 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 1 Jan 2019 13:03:08 +0000 Subject: 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 --- www/git.causal.agency/cgit/cache.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'www/git.causal.agency/cgit/cache.c') diff --git a/www/git.causal.agency/cgit/cache.c b/www/git.causal.agency/cgit/cache.c index 2c70be78..580c0e80 100644 --- a/www/git.causal.agency/cgit/cache.c +++ b/www/git.causal.agency/cgit/cache.c @@ -265,6 +265,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)) { -- cgit 1.4.1