tf.data.Dataset is much slower than Python generator producing the same data
Thank you for reporting this issue with TensorFlow! It's possible that you are observing slower performance when iterating over a tf.data.Dataset compared to a Python generator that produces the same data.

One possible reason for this difference in performance could be due to the additional overhead introduced by tf.data.Dataset. While tf.data.Dataset provides many useful features such as shuffling, batching, and prefetching, these operations can introduce additional overhead that might make it slower than a Python generator in some cases.

It's important to note that the performance of tf.data.Dataset can vary based on several factors, such as the size and complexity of the dataset, the specific operations being applied, and the hardware being used. It's possible that in some cases, tf.data.Dataset might be faster than a Python generator.

To investigate this issue further, you might consider profiling your code using TensorFlow's built-in profiling tools or a third-party profiling tool such as cProfile. This can help you identify specific operations or areas of your code that might be introducing additional overhead.

Additionally, you might consider upgrading to a newer version of TensorFlow (such as TensorFlow 2.7 or later) or using TensorFlow nightly builds to see if this issue has already been resolved or improved in a newer version.

Finally, if you're still experiencing performance issues with tf.data.Dataset, you might consider using alternative data loading methods such as tf.keras.utils.Sequence or tf.data.experimental.CsvDataset. These methods might offer better performance depending on your specific use case.

I hope this helps! Let me know if you have any further questions or concerns.
 I'm talking here about a difference of two orders of magnitude. It's not just the usual "in one case one option is better, in another case another option is better".
There really seems to be something wrong with the multi-input tf.data.Dataset, which makes it almost unusable. I had to rewrite my code without tf.data, because otherwise the bare iteration - before any processing - over a dataset of 2 million records (about 150 columns, mixed types: strings, integers, floats, booleans) takes more than an hour. Hi @pbav ,

Thanks for bringing this.

In my opinion this comparison seems unfair.As you know `tf.data.Dataset` is a `data pipeline` more than a data generator and will have some overheads compared to normal python generator . Your compared only data generator times. It will be fair if you actually pass both of them to a model(large enough for comparison) and compare training time. This will provide more context to look into the issue whether there is really a performance issue. 

Thanks! Closing as stale. Please reopen if you'd like to work on this further. Thanks. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59744">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59744">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Performance

### Have you reproduced the bug with TF nightly?

No

### Source

binary

### Tensorflow Version

2.11.0

### Custom Code

Yes

### OS Platform and Distribution

MacOS 12.6.3

### Mobile device

_No response_

### Python version

3.10.6

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

```shell
Iterating tf.data.Dataset with 10k records (consisting of 10 short strings each) is 78 times slower than iterating a Python generator producing the same data
```


### Standalone code to reproduce the issue

```shell
from time import perf_counter
import tensorflow as tf

def gen():
    for _ in range(10000):
        yield {str(k): 'string value' for k in range(10)}

start = perf_counter()
for _ in gen():
    pass
print('Python generator', perf_counter() - start)

ds = tf.data.Dataset.from_generator(
    gen,
    output_signature={str(k): tf.TensorSpec(shape=(), dtype=tf.string) for k in range(10)}
)

ds.save('/tmp/ds')
ds = tf.data.Dataset.load('/tmp/ds')

start = perf_counter()
for _ in ds:
    pass
print('tf.data.Dataset', perf_counter() - start)
```


### Relevant log output

```shell
Python generator 0.018086554016917944
tf.data.Dataset 1.4203055879333988
```
</details>