I have a ruby hash (possibly huge) that contains time-based (keys) and string data values.
def time_now
Time.now.utc.iso8601(3)
end
time_1 = time_now #=> "2014-12-04T10:05:07.852Z"
data_1= "{\"data\": \"some possibly big json data as string\"}"
h = { time_1 => data_1, ... }
so in my app (BTW, here the full code: http://github.com/solyaris/pere) I used as keys just ISO8601 string timestamp.
That's maybe ok, but ...
for some reasons I have to select in run-time a subset of hash items; that imply key string comparisons:
h.select { |key, value| key > some__string_timestamp }
So, to have some memory optimizations, and faster execution, possibly STRINGS as key are not the best solution.
I thinked about using symbols:
time_1_key_as_symbol = time_1.intern
But here I have a problem: considering hash could contain a big amount of keys items (these are timestamps of realtime "cluster" events...), having as keys just symbols, could create memory overflow problems because the lack of garbage collection on symbols on Ruby (if I well understood, see also: Why use symbols as hash keys in Ruby? )
So I concluded that could be better (for faster comparisons and memory optimization) to use as keys the internal Ruby Time
internal format (64bit by Ruby version 2.1?) instead of strings:
time_1_as_ruby_time = Time.iso8601 time_1
Correct ? What do you think about ?