Most weather data sources give you an array of hashes (representing hours or days) with data points like so:
[
{
temperature: 73,
windSpeed: 10,
},
{
temperature: 70,
windSpeed: 15,
},
]
...but The Weather Company gives you a hash of arrays, like so:
{
temperature: [73, 70, ...],
windSpeed: [10, 15, ...],
}
Iterating over a large hash of arrays and digging out values by array index turns out to be really slow -- much better to convert the hash of arrays into an array of hashes and then map... but why?
Change resulted in a massive speedup (1000ms -> 200ms) and much better memory usage on Heroku