When large amounts of data need to be changed on disk in pieces, use a database and store the pieces as rows. Sqlite is a good one to start with if you haven't used them before. This applies to almost all languages, since programming languages very rarely have a built-in database. There are many Rust crates for accessing databases.
I used SQLite in previous project. I thought of it before, but I need the best time access as possible to my data.
I know that SQLite is very good in terms of performance, but I'm making the assumption that it can't be better than an in-memory vector. Maybe I'm wrong? Or that there's no middle ground anyway?
If you read the data from Sqlite you can still create an in-memory vector, if that's what you think is necessary to get the performance you need.
The point of using a database is being able to update it on disk without rewriting the entire file -- that's what you said you wanted.
If you don't use a database for that, you could split it up into multiple files so you can write smaller files. When writing smaller pieces, you will have to serialize each part separately -- this is true whether they are separate files or separate rows in a database. How to separate it into smaller pieces is the thing you need to figure out, since how you do this is application specific.
First, SQLite (as almost any serious database) has in-memory caching built-in.
Second, even if it didn't, you could make it yourself.
You can always just collect a small diff of the most recent changes and issue the corresponding queries (while potentially keeping a separate copy of your entire data in memory, if you wish.) How do you think the frontend of a web application manages to update the state without having to store and re-write the entire (potentially multi-TB) data every time?
I know usage of a database. And, by my experience of them, I know they can be very performant. But, I also know that a serialization step is required for input/output. Which will have performance impact.
Aren't you doing serialization with bincode anyway?
Another thing you haven't mentioned is whether you need to be able to read the data from disk after a crash. If so, you definitely need a database for that. If you crash while writing data, data on disk may be inconsistent (partially written). Recovering from that situation is the problem that databases and transactions are made to solve.
My critical performance point is read access of data. So I don't have serialization when my data is in RAM.
You have a good point about data consistence when disk write. I will consider the performance benchmark about read access and consider keeping a separate copy of my entire data solution.