Skip to content

Commit

Permalink
tvg-render: use bufferedReader for 10x performance boost in parsing
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
marler8997 authored and ikskuh committed Jul 30, 2024
1 parent d771f6d commit ed01b91
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/tools/render.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -129,7 +130,7 @@ pub fn main() !u8 {
else
.inherit,
@enumFromInt(super_scale),
source_file.reader(),
buffered_reader.reader(),
);
defer image.deinit(allocator);

Expand Down

0 comments on commit ed01b91

Please sign in to comment.