Is there an advantage to holding on to a dataset loader?

Consider the following two algorithms with regards to the constructing the dataset loader:

  1. Before looping through the training epochs
  2. Within the loop for each epoch

Does the first algorithm have a SIGNIFICANT advantage over the second one?

In general: No it hasn’t. However, I try to reduce repeatedly executed code to a necessary minimum. Saying that I usually initialize it before the loop since there are no disadvantages doing so.