From ed01b91128821b061ae22194b3473ae8b5d268fe Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Tue, 30 Jul 2024 08:55:55 -0600 Subject: [PATCH] tvg-render: use bufferedReader for 10x performance boost in parsing I took a profile of tvg-render and found that parsing the file took about 68% of the time. This was surprising as I would have expected rendering to take longer. The profile revealed that most of time was spent in the filesystem read syscalls. I've seen this problem before and the solution in the past has been to use a buffered reader rather than the file reader directly. After adding the buffered reader the parse time went from about 2 ms to about 200 microseconds (10x improvement). --- src/tools/render.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tools/render.zig b/src/tools/render.zig index df34af2..d21b6fb 100644 --- a/src/tools/render.zig +++ b/src/tools/render.zig @@ -114,6 +114,7 @@ pub fn main() !u8 { } // TODO: Render here + var buffered_reader = std.io.bufferedReader(source_file.reader()); var image = try tvg.rendering.renderStream( allocator, @@ -129,7 +130,7 @@ pub fn main() !u8 { else .inherit, @enumFromInt(super_scale), - source_file.reader(), + buffered_reader.reader(), ); defer image.deinit(allocator);