#Slow IO: debugging help requested

1 messages · Page 1 of 1 (latest)

sand halo
#

Hi all! I’ve got a function that is suprisingly slow. 80% of my program’s execution is spent in this function:
https://codeberg.org/denis_defreyne/tomatenmark_zig/src/commit/c16b4f83120c22949240c712afa97a8ce4ede612/src/root.zig#L816-L850

See the screenshot for a performance profile. readByte is slow despite reading from a buffered reader. It seems like the buffered reader itself is rather slow? I’m not sure how to optimize this. Thoughts?

Semi-related: This is part of a pull parser, which would make async I/O rather useful here. Reading the file and parsing can happen in parallel. Is it worth looking into async IO or wait until Zig 0.15 with the async IO changes?

smoky tundra
#

I think the self-weight here is more descriptive. The buffered reader takes up the most time which makes sense, since it's waiting on disk IO for up to 4096 bytes to fill up it's buffer. That also slows down all other functions that depend on it hence why readByte takes up 80% of execution time.

40ms seems alright for disk IO. what kind of storage medium are you using? you can try reading the file from /tmp, probably will be far faster.

async io would only be practical if there is something to do in parallel while the IO is yielding.

regal seal
#

0.15 probably wont take much longer to come out
Though it will not have the new IO interface and async. Thats for 0.16.

sand halo
#

Makes sense! This isn’t a big deal, and mostly me being curious.

#

I can wait until 0.16 too!