If you can point us to the code and a description of the setup (what kind of display we need to use), I'll pass this info along so that we can see if the hardware is generating invalid waveforms at some point.
It's not so much the code that matters as the device under test does. A display gets far more traffic than a sensor, so the glitches are more obvious and occur much more quickly. Some kind of loopback test might work better (or it might not work at all) but I've not devised one yet.
It would be ideal if we were testing the same I2C device: something that can take a lot of I2C traffic, is obvious when it glitches, and which doesn't require interrupts (which can complicate things). I've got a few ideas though...
I just want to drop a line here. I'm also seeing similar problems like MartyMacGyver. In my case I'm using an I2C based IR-sensor. It works for a few minutes, and then the ESP32 looses connection with the device.
While I am concerned about the unusual sensitivity of I2C on the the ESP32 to load (it takes very little to make the output frequency vary, especially at 400kHz) I don't think that's the main issue.
Extra capacitance across between VDD and GND (47uF or so) would help rule out power-related issues (IR LEDs draw a fair amount of current).
I assume the sensor is being tested in isolation so no other i2c devices are present. I don't see pull-up resistors on the breakout board I looked at (
http://www.robot-electronics.co.uk/file ... e02b_e.pdf) - what value of pull-up resistors are you using for this? (Typical value is 4.7Kohm).
Edit: One reference I looked at was
https://github.com/NorbotNorway/TeensyAndGP2Y0E02B... I just noticed you're a contributor there so you're probably already aware of all this. Still, would be good to know what value you used in this case (1K is pretty strong IMHO but there's a lot that goes into that calculation - and as long as it's somewhere between 1K and 4.7K I don't think it really matters to the ESP32 problem).
If you rule out those potential problems and are still seeing the issue, then it gets more interesting. An advantage is your sensor is a lot like my display: just SCL and SDA. Since you're Teensy-savvy, is the same sensor rock-solid on that ARM device?
On a related note, I turned on my STM32-based Particle last night, running the OLED. It's been running test patterns for 10 hours and still no glitches (the glitches seen with the ESP32 are somewhat cumulative - once you get out of sync it tends to get worse from there).