Each worker in the DataLoader will create a batch by calling into Dataset.__getitem__ with the corresponding index and will add the batch to the queue.
It depends on your use case, if using a DataLoader (with multiple workers) would yield a speedup.
E.g. if you are preloading the entire dataset, are just returning the sample in __getitem__, and don’t need a custom collate_fn or a specific sampler, the DataLoader's overhead might be visible and your use case might be faster by directly indexing the Dataset with (random) indices.
However, if you are adding some transformations to each preloaded sample etc. the DataLoader might still be beneficial, especially if the augmentation is done in the background, so you would need to profile both approaches.