Very simple use case.
Some data pre-loaded in memory. I just fetch each sample directly from memory
from torch.utils.data import Dataset, DataLoader
import numpy as np

class NpDataset(Dataset):
    def __init__(self, n, m):
        self.X = np.random.rand(n, m)
        self.Y = np.random.rand(n, m)
        
    def __getitem__(self, index):
        return self.X[index], self.Y[index]
    
    def __len__(self):
        return self.X.shape[0]

I create such a dataset with 100,000 samples of size 1000
ds = NpDataset(100_000, 1000)
then if I iterate over it using dataloader, using multiple workers does not improve the speed of the iteration:
loader = DataLoader(ds, batch_size=100, num_workers=4, shuffle=True, pin_memory=False)
for x, y in loader:
    pass

takes 3.7s
while with num_workers=0 it takes only 2s.
Any idea why in such a case multiple workers does not improve the speed?