adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.12k stars 1.22k forks source link

Intermittent Delay while reading Capacitive Touch: heap size related #8692

Open makermelissa opened 11 months ago

makermelissa commented 11 months ago

CircuitPython version

Adafruit CircuitPython 9.0.0-alpha.5 on 2023-11-15; Adafruit-Qualia-S3-RGB666 with ESP32S3

Code/REPL

See https://github.com/adafruit/Adafruit_CircuitPython_Qualia/blob/main/examples/qualia_paint.py

Behavior

After about every 10 reads or so from the capacitive touch screen, there is a noticeable delay. You can really tell by running the paint program: IMG_5512

Description

Additional information

Switching to CP Alpha 2 fixes the issue. With CP Alpha 4, the problem is there, but you need to make sure the PYSTACK size and such is big enough to run it. My guess is it's related to the split heap stuff.

Using different touch drivers, touch controllers, and optimizing code did not help.

tannewt commented 11 months ago

My guess is that we're doing a collect when the heap is full to see if we can allocate into it (and we can.) This will happen earlier with split heap than it did with the one big heap. The pauses should be shorter though.

tannewt commented 11 months ago

Raising the starting heap size may give you enough buffer to capture a full finger drag before triggering the GC. You could also try running gc.collect() when a finger isn't active.

makermelissa commented 11 months ago

Ok, I'll try those to see if it helps...

makermelissa commented 11 months ago

Raising starting heap size did help. Garbage collection didn't help.

tannewt commented 10 months ago

Do we want a larger default heap? This seems like a pretty specific case to change a default for.

tannewt commented 9 months ago

Raising starting heap size did help. Garbage collection didn't help.

What did you set it to? 128k? We could make it default on PSRAM builds.

makermelissa commented 9 months ago

Tested this on latest CP 9 version and 512K seemed to work better than 128K or 256K.

tannewt commented 9 months ago

Thanks for the update! I've moved this to 9.x.x. I'd like to see if any other uses like this crop up before we change the default heap size. Having it in stable should make it clearer.