Cost of File open/close

⚓ rust    📅 2025-07-06    👤 surdeus    👁️ 2      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Cost of File open/close

I have a server where, every so many requests, the state of the server is written to a file.

Currently, every time I write to the file the File is opened and closed.

The File could be opened at server start, stored in a struct that stays in scope for the life of the server (the File never closes), and then be written to without having to open/close it each time.

I think this would improve the performance of the writes, but Im not sure exactly what the performance cost of the open/closes that I'm eliminating are. Does anyone have insight into this?

Also, is keeping a File open too long dangerous and/or not worth the savings?

6 posts - 3 participants

Read full topic

🏷️ rust_feed