-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CircuitPython 4.x Performance issue with the pygamer vs. MicroPython #1933
Comments
This doesn't surprise me because performance hasn't been our focus. I'll probably take a glance for simple improvements in the next couple weeks but we'd totally take PRs that improve things. |
I did some research on this. I looked at the stm32 port settings in MicroPython. In our ports, we use If do not define the I could only test this in CircuitPython 3.1.2. It works at least for a short while without calling background tasks frequently, but eventually the REPL connection goes away. CircuitPython 4.0.1 doesn't work at all if I eliminate the background task call. That accounts for a large fraction of your performance difference, but not all, and further research would uncover more. |
Thanks Dan! Interesting findings! "This happens after every jump opcode and every return" looks pretty scary :) so everything happens here, ans especially usb_background(), right? #define MICROPY_VM_HOOK_LOOP run_background_tasks();
#define MICROPY_VM_HOOK_RETURN run_background_tasks();
void run_background_tasks(void) {
// Don't call ourselves recursively.
if (running_background_tasks) {
return;
}
assert_heap_ok();
running_background_tasks = true;
#if (defined(SAMD21) && defined(PIN_PA02)) || defined(SAMD51)
audio_dma_background();
#endif
#if CIRCUITPY_DISPLAYIO
displayio_refresh_displays();
#endif
#if CIRCUITPY_NETWORK
network_module_background();
#endif
filesystem_background();
usb_background();
running_background_tasks = false;
assert_heap_ok();
last_finished_tick = ticks_ms;
} And yep MICROPY_VM_HOOK_* are called in a lot of places... |
Further testing: I have turned on The basic test I am using (to avoid any issues about how
|
Interesting ! I'll try tonight on my pygamer to enable MICROPY_OPT_COMPUTED_GOTO and disable CIRCUITPY_DISPLAYIO. I'll post my results here. |
@dhalbert, with the last CircuitPython source code, when I add In file included from ../../py/vm.c:129:0:
../../py/vmentrytable.h:27:5: error: "__clang__" is not defined, evaluates to 0 [-Werror=undef]
#if __clang__
^~~~~~~~~
../../py/vmentrytable.h:116:5: error: "__clang__" is not defined, evaluates to 0 [-Werror=undef]
#if __clang__
^~~~~~~~~
cc1: all warnings being treated as errors
make: *** [../../py/mkrules.mk:82: build-pygamer/genhdr/qstr.i.last] Error 123 Anything I should do ? |
Change both |
Note the PR: #1934 |
Thanks! So I ran again the same test with Results: So a huge improvement but still some room for optimization to reach the ~10ms on an equivalent 120MHz STM32F4 board with MicroPython. Good job @dhalbert ! |
Thanks! The next step is more work, which is to figure out how to call the background tasks only as often as necessary. That will get the next 2-3x speedup, I think. |
We really appreciate your taking the time to do this comparison and point out the big disparity. |
Just tried at 200Mhz: 21.2 ms. Ah ah, no issue :) It forces me to go into the details to get a better understanding of CircuitPython, I like that. But a beer in the Walking City downtown would be appreciated too :) |
Closing in favor of #2142. |
trying with got |
Hi,
I did a simple loop test in python to compare with my STM32F4 based MicroPython board and the results are quite unexpected. CircuitPython 4.x is 16x slower than MicroPython for an equivalent CPU frequency.
Details available here:
https://forums.adafruit.com/viewtopic.php?f=60&t=152372&p=753830#p753830
Test code:
Results:
C module reference:
Results:
Real issue or I did something wrong ?
The text was updated successfully, but these errors were encountered: