I have many arrays of longs long[]
and I need to serialize them and save them to disk for later read, notice that each array has to be modified from time to time, but writes are infrequent while reads are frequent.
Usually my application needs only a small number of those loaded into memory at the same time.
Edits to each array can happen in batch in memory before the array are stored back to disk.
Each array has from hundreds up to a million elements.
In my application it is critical that loading the desired arrays into memory happens very fast.
In my case the long values in each array are, on average, quite near one to the other, i.e., the difference from one value to the next - if sorted within a single array- is less than an integer.
The solution adopting a trie-like structure as presented here seems not applicable for my case, since in that solution the array values are known and never change.
This solution here tells me to use ByteBuffer
and LongBuffer
to speed up I/O, but my idea would be to also store such arrays in the most compact way in order to speed-up the time needed to load them into main memory by reducing the size of what I need to read.
The intuition is to store the values sorted and store the difference between one value and the next one, which is - on average- within the Integer range and as such take less space.
But since this is not always true, I still cannot store all the values as integers, so this direction doesn't seem promising.
Am I missing something obvious?
What is the most efficient way, in I/O time, to achieve this?
EDIT In general, regarding performance as solely I/O time, without considering space on disk, this question has better answers.