Skip to content

machine/esp32: do not allocate on each I2C transaction - #5922

Merged
deadprogram merged 1 commit into
devfrom
esp32-i2c-noalloc
Oct 19, 2026
Merged

deadprogram merged 1 commit into
devfrom
esp32-i2c-noalloc

Conversation

@deadprogram

@deadprogram deadprogram commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

transmit in machine_esp32xx_i2c.go cleaned up the interrupt bits with a deferred closure, which allocated on every I2C transaction. A program that polls I2C sensors in a loop then keeps triggering the GC.

This moves the command loop into a helper and does the cleanup after it returns, so every return path still clears the interrupt bits.

Tested

On an M5Stack StampFly reading a BMP280, BMM150, VL53L3CX and INA3221 over I2C, allocations from I2C went from about 200 per second to none, and all four sensors still read correctly.

examples/blinkm builds for xiao-esp32c3, xiao-esp32c6 and xiao-esp32s3, and for m5stamp-fly from #5921.

@github-actions

Copy link
Copy Markdown

Size difference with the dev branch:

Binary size difference
 flash                          ram
 before   after   diff          before   after   diff
  18772   18772      0   0.00%    6876    6876      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/adafruit4650
  63916   63916      0   0.00%    6884    6884      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adt7410/main.go
  11436   11436      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adxl345/main.go
  15612   15612      0   0.00%    7492    7492      0   0.00% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/amg88xx
  10668   10668      0   0.00%    5396    5396      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/main.go
  13948   13948      0   0.00%    7252    7252      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/apds9960/proximity/main.go
  12872   12872      0   0.00%    5408    5408      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/itsybitsy-m0/main.go
   8856    8856      0   0.00%    2320    2320      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/at24cx/main.go
  10156   10156      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bh1750/main.go
   9452    9452      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/blinkm/main.go
  72432   72432      0   0.00%    3720    3720      0   0.00% tinygo build -size short -o ./build/test.hex -target=pinetime     ./examples/bma42x/main.go
  68540   68540      0   0.00%    6852    6852      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmi160/main.go
  29292   29292      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp180/main.go
  67196   67196      0   0.00%    6884    6884      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp280/main.go
  13852   13852      0   0.00%    5468    5468      0   0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bmp388/main.go
  23092   23092      0   0.00%    6116    6116      0   0.00% tinygo build -size short -o ./build/test.hex -target=metro-rp2350 ./examples/bno08x/i2c/main.go
   9256    9256      0   0.00%    3360    3360      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/sram/main.go
  23108   23108      0   0.00%    3592    3592      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/time/main.go
  31704   31704      0   0.00%    5668    5668      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/ds3231/alarms/main.go
  45576   45576      0   0.00%    5668    5668      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/ds3231/basic/main.go
   4776    4776      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/easystepper/main.go
   6992    6992      0   0.00%    2344    2344      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/easystepper/async/main.go
  73808   73808      0   0.00%    7712    7712      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/flash/console/spi
  69568   69568      0   0.00%    9752    9752      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/flash/console/qspi
   7556    7556      0   0.00%    2284    2284      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/gc9a01/main.go
  23680   23680      0   0.00%    8588    8588      0   0.00% tinygo build -size short -o ./build/test.bin -target=esp32-coreboard-v2 ./examples/gdew0154m09/main.go
  70256   70256      0   0.00%    7084    7084      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/i2c/main.go
  70744   70744      0   0.00%    7188    7188      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/uart/main.go
  10228   10228      0   0.00%    5460    5460      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/hcsr04/main.go
   5896    5896      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hd44780/customchar/main.go
   5976    5976      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hd44780/text/main.go
  12188   12188      0   0.00%    5420    5420      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/hd44780i2c/main.go
  16828   16828      0   0.00%    7252    7252      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/hts221/main.go
  16580   16580      0   0.00%    2428    2428      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hub75/main.go
  11772   11772      0   0.00%    7636    7636      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/basic
  14252   14252      0   0.00%    5596    5596      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/ili9341/basic
  31140   31140      0   0.00%   38796   38796      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/pyportal_boing
  11748   11748      0   0.00%    7636    7636      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/scroll
  14276   14276      0   0.00%    5596    5596      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/ili9341/scroll
 266636  266636      0   0.00%   47480   47480      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/slideshow
  12492   12492      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis3dh/main.go
  16236   16236      0   0.00%    7252    7252      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/lps22hb/main.go
  26616   26616      0   0.00%    2328    2328      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/lsm303agr/main.go
  29900   29900      0   0.00%    7484    7484      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/lsm303dlhc/main.go
  14140   14140      0   0.00%    5444    5444      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/lsm6ds3/main.go
  12716   12716      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mag3110/main.go
  11556   11556      0   0.00%    5428    5428      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp23017/main.go
  11988   11988      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp23017-multiple/main.go
  11868   11868      0   0.00%    5396    5396      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp3008/main.go
  74980   74980      0   0.00%    6964    6964      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp2515/main.go
  30776   30776      0   0.00%    4152    4152      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/microbitmatrix/main.go
  30680   30680      0   0.00%    6196    6196      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit-v2 ./examples/microbitmatrix/main.go
  10188   10188      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mma8653/main.go
  10140   10140      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mpu6050/main.go
  80204   80204      0   0.00%    8124    8124      0   0.00% tinygo build -size short -o ./build/test.hex -target=p1am-100 ./examples/p1am/main.go
  14232   14232      0   0.00%    6056    6056      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/pca9685/main.go
   6692    6692      0   0.00%    3292    3292      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setbuffer/main.go
   5092    5092      0   0.00%    2284    2284      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setpixel/main.go
  14280   14280      0   0.00%    6040    6040      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/seesaw/soil-sensor
  13864   13864      0   0.00%    6040    6040      0   0.00% tinygo build -size short -o ./build/test.hex -target=qtpy-rp2040 ./examples/seesaw/rotary-encoder
   2899    2899      0   0.00%     560     560      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino ./examples/servo
  15856   15856      0   0.00%    6120    6120      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico     ./examples/sgp30
   9564    9564      0   0.00%    7436    7436      0   0.00% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/shifter/main.go
  59072   59072      0   0.00%    3728    3728      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht3x/main.go
  59024   59024      0   0.00%    3728    3728      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht4x/main.go
  59072   59072      0   0.00%    3728    3728      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/shtc3/main.go
  15060   15060      0   0.00%    9132    9132      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao-ble ./examples/ssd1306/
  13736   13736      0   0.00%    6080    6080      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao-rp2040 ./examples/ssd1306/
  13688   13688      0   0.00%    6072    6072      0   0.00% tinygo build -size short -o ./build/test.hex -target=thumby ./examples/ssd1306/
   6388    6388      0   0.00%    2284    2284      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1331/main.go
   7236    7236      0   0.00%    2284    2284      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7735/main.go
   6932    6932      0   0.00%    2284    2284      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7789/main.go
  18844   18844      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/thermistor/main.go
  12764   12764      0   0.00%    5220    5220      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-bluefruit ./examples/tone
  12108   12108      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/tm1637/main.go
  12716   12716      0   0.00%    6052    6052      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/touch/capacitive
  10932   10932      0   0.00%    7428    7428      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/touch/resistive/fourwire/main.go
  13952   13952      0   0.00%    7696    7696      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/touch/resistive/pyportal_touchpaint/main.go
  17284   17284      0   0.00%    5508    5508      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl53l1x/main.go
  15956   15956      0   0.00%    5508    5508      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl6180x/main.go
  27208   27208      0   0.00%   14408   14408      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840-sense ./examples/waveshare-epd/epd1in54/main.go
   6804    6804      0   0.00%    2324    2324      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13/main.go
   6484    6484      0   0.00%    2316    2316      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13x/main.go
   6676    6676      0   0.00%    2324    2324      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd4in2/main.go
  29896   29896      0   0.00%   19112   19112      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/waveshare-epd/epd2in66b/main.go
   8780    8780      0   0.00%    5428    5428      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/ws2812
   6122    6122      0   0.00%    8464    8464      0   0.00% tinygo build -size short -o ./build/test.bin -target=m5stamp-c3          ./examples/ws2812
  66004   66004      0   0.00%    6636    6636      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840 ./examples/is31fl3731/main.go
   1799    1799      0   0.00%     600     600      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino   ./examples/ws2812
   1280    1280      0   0.00%     182     182      0   0.00% tinygo build -size short -o ./build/test.hex -target=digispark ./examples/ws2812
   7776    7776      0   0.00%    8744    8744      0   0.00% tinygo build -size short -o ./build/test.bin -target=xiao-esp32c3 ./examples/ws2812
  33516   33516      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bme280/main.go
  18372   18372      0   0.00%    5380    5380      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/microphone/main.go
  13116   13116      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/buzzer/main.go
  14092   14092      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/veml6070/main.go
   8540    8540      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l293x/simple/main.go
  10476   10476      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l293x/speed/main.go
   8508    8508      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l9110x/simple/main.go
  10908   10908      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l9110x/speed/main.go
   8180    8180      0   0.00%    3324    3324      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-f103rb ./examples/shiftregister/main.go
   7596    7596      0   0.00%    2288    2288      0   0.00% tinygo build -size short -o ./build/test.hex -target=hifive1b ./examples/ssd1351/main.go
  15308   15308      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis2mdl/main.go
  13004   13004      0   0.00%    5412    5412      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/max72xx/main.go
  80412   80412      0   0.00%    7032    7032      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/dht/main.go
  39236   39236      0   0.00%    6620    6620      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/pcf8523/
  73580   73580      0   0.00%    7072    7072      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/alarm/
   9132    9132      0   0.00%    5428    5428      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/clkout/
  68312   68312      0   0.00%    7068    7068      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/time/
  73420   73420      0   0.00%    7072    7072      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/timer/
  14440   14440      0   0.00%    6048    6048      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/qmi8658c/main.go
  13000   13000      0   0.00%    6040    6040      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/pcf8591/
  10668   10668      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/ina260/main.go
  14828   14828      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/ina219/main.go
  10600   10600      0   0.00%    5280    5280      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-l432kc ./examples/aht20/main.go
  77028   77028      0   0.00%   11508   11508      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/sdcard/console/
  63516   63516      0   0.00%    8892    8892      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/i2csoft/adt7410/
  11772   11772      0   0.00%    7444    7444      0   0.00% tinygo build -size short -o ./build/test.elf -target=wioterminal ./examples/axp192/m5stack-core2-blinky/
  10804   10804      0   0.00%    5980    5980      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/xpt2046/main.go
  12460   12460      0   0.00%    4692    4692      0   0.00% tinygo build -size short -o ./build/test.elf -target=m5stack-core2 ./examples/ft6336/basic/
  20040   20040      0   0.00%    4964    4964      0   0.00% tinygo build -size short -o ./build/test.elf -target=m5stack-core2 ./examples/ft6336/touchpaint/
  14416   14416      0   0.00%    5060    5060      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/sx126x/lora_rxtx/
  47288   47288      0   0.00%    9608    9608      0   0.00% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/sx127x/lora_rxtx/
  36400   36400      0   0.00%    7760    7760      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/ssd1289/main.go
  13496   13496      0   0.00%    7032    7032      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/irremote/main.go
  14304   14304      0   0.00%    6056    6056      0   0.00% tinygo build -size short -o ./build/test.hex -target=badger2040 ./examples/uc8151/main.go
  14080   14080      0   0.00%    6500    6500      0   0.00% tinygo build -size short -o ./build/test.hex -target=badger2040 ./examples/waveshare-epd/epd2in9v2/main.go
  15964   15964      0   0.00%    6092    6092      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/scd30/main.go
  12552   12552      0   0.00%    6060    6060      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/scd4x/main.go
   9684    9684      0   0.00%    5396    5396      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=circuitplay-express ./examples/makeybutton/main.go
  11388   11388      0   0.00%    5412    5412      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ds18b20/main.go
 125716  125716      0   0.00%    8448    8448      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/lora/lorawan/atcmd/
  18372   18372      0   0.00%    7644    7644      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/as560x/main.go
  13704   13704      0   0.00%    6040    6040      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mpu6886/main.go
   9548    9548      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ttp229/main.go
  70328   70328      0   0.00%    7528    7528      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/ndir/main_ndir.go
  63736   63736      0   0.00%    3792    3792      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ndir/main_ndir.go
  68252   68252      0   0.00%    6924    6924      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ndir/main_ndir.go
  11400   11400      0   0.00%    6032    6032      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mpu9150/main.go
  13508   13508      0   0.00%    6100    6100      0   0.00% tinygo build -size short -o ./build/test.hex -target=macropad-rp2040 ./examples/sh1106/macropad_spi
  10352   10352      0   0.00%    6472    6472      0   0.00% tinygo build -size short -o ./build/test.hex -target=macropad-rp2040 ./examples/encoders/quadrature-interrupt
  68680   68680      0   0.00%    7488    7488      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mcp9808/main.go
  46128   46128      0   0.00%    8136    8136      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/tmc2209/main.go
  14084   14084      0   0.00%    5988    5988      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/tmc5160/main.go
  14720   14720      0   0.00%    5216    5216      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=nicenano ./examples/sharpmem/main.go
  65016   65016      0   0.00%    6664    6664      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840 ./examples/max6675/main.go
  14872   14872      0   0.00%    6048    6048      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/ens160/main.go
  18416   18416      0   0.00%    6152    6152      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/si5351/main.go
  23856   23856      0   0.00%    7400    7400      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/w5500/main.go
  91656   91656      0   0.00%    7844    7844      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/sd
  90572   90572      0   0.00%    7932    7932      0   0.00% tinygo build -size short -o ./build/test.hex -target=challenger-rp2040 ./examples/net/ntpclient/
 379424  379424      0   0.00%   14888   14888      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal -stack-size 8kb ./examples/net/http-get/
 127012  127012      0   0.00%    9080    9080      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 -stack-size 8kb ./examples/net/tcpclient/
 357908  357908      0   0.00%   13368   13368      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-rp2040 -stack-size 8kb ./examples/net/websocket/dial/
 108968  108968      0   0.00%   11060   11060      0   0.00% tinygo build -size short -o ./build/test.hex -target=metro-m4-airlift -stack-size 8kb ./examples/net/socket/
 426904  426904      0   0.00%   17564   17564      0   0.00% tinygo build -size short -o ./build/test.hex -target=matrixportal-m4 -stack-size 8kb ./examples/net/webstatic/
 172912  172912      0   0.00%    9248    9248      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-mkrwifi1010 -stack-size 8kb ./examples/net/tlsclient/
 163044  163044      0   0.00%    9836    9836      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-rp2040 -stack-size 8kb ./examples/net/mqttclient/natiu/
 122932  122932      0   0.00%   14372   14372      0   0.00% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/webclient/
 375348  375348      0   0.00%   20020   20020      0   0.00% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/webserver/
 373988  373988      0   0.00%   19080   19080      0   0.00% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/mqttclient/paho/
 179880  179880      0   0.00%   12312   12312      0   0.00% tinygo build -size short -o ./build/test.hex -target=elecrow-rp2040 -stack-size 8kb ./examples/net/tlsclient/
 126196  126196      0   0.00%   12140   12140      0   0.00% tinygo build -size short -o ./build/test.hex -target=elecrow-rp2350 -stack-size 8kb ./examples/net/ntpclient/
7017056 7017056      0   0.00% 1110458 1110458      0   0.00%

@deadprogram deadprogram added this to the 0.44 milestone Oct 18, 2026
Comment thread src/machine/machine_esp32xx_i2c.go Outdated
Comment thread src/machine/machine_esp32xx_i2c.go Outdated
Comment thread src/machine/machine_esp32xx_i2c.go Outdated
Comment thread src/machine/machine_esp32xx_i2c.go Outdated
Comment thread src/machine/machine_esp32xx_i2c.go Outdated
Comment thread src/machine/machine_esp32xx_i2c.go Outdated
Comment thread src/machine/machine_esp32xx_i2c.go Outdated
transmit cleaned up the interrupt bits with a deferred closure, which
allocated on every transaction. Run the commands in a helper and clean
up after it returns instead.

On an M5Stack StampFly reading four I2C sensors, allocations from I2C
went from about 200 per second to none.
@deadprogram

Copy link
Copy Markdown
Member Author

Thanks @davecheney

  1. Done, the local intMask constants are gone and the code uses i2cIntMask directly.

  2. The clear inside the loop was already there before this PR. It is needed between command batches that stop on END, since the next wait polls INT_STATUS and would see the old TRANS_COMPLETE bit. The clear in transmit covers the error returns. So after the last batch it does run twice. I would rather keep this PR to the allocation fix, but I can clean up who clears what in a follow-up if you like.

@davecheney davecheney left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@davecheney

Copy link
Copy Markdown
Contributor

Thanks @davecheney

  1. Done, the local intMask constants are gone and the code uses i2cIntMask directly.
  2. The clear inside the loop was already there before this PR. It is needed between command batches that stop on END, since the next wait polls INT_STATUS and would see the old TRANS_COMPLETE bit. The clear in transmit covers the error returns. So after the last batch it does run twice. I would rather keep this PR to the allocation fix, but I can clean up who clears what in a follow-up if you like.

Yup. I should have been clearer that this was just an observation, not something to address

@deadprogram

Copy link
Copy Markdown
Member Author

Thank you for reviewing @davecheney now merging.

@deadprogram
deadprogram merged commit e165a4f into dev Oct 19, 2026
40 checks passed
@deadprogram
deadprogram deleted the esp32-i2c-noalloc branch October 19, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants