BarCodeReader:

when we load a batch, will it become slower just because we keep generating the index? because I created a notebook to test this and it seems when batch size is large, the index will get printed so many times.


No, that shouldn’t be the case as the index generation should be really cheap in comparison to the data loading and processing. The batch is calculated by calling __getitem__ with batch_size indices.
E.g. for a batch size of 128 the DataLoader would call Dataset.__getitem__ 128 times and thus you would see the index output 128 times.



 BarCodeReader:

but I just dont know if this kind of “slow” is because we have large batch, or becuase the loader generate index many times thus introduce some extra loading time.


Most likely you see the slowdown due to the data loading and processing.
Note that multiple workers would potentially hide this latency in the background after the first iteration started.