From 677a0e01248bc7075f342c7df9671b006bf76c89 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 17 Jul 2025 15:04:14 +1000 Subject: [PATCH] docs/reference/speed_python: Document schedule/GIL limitation of native. Signed-off-by: Damien George --- docs/reference/speed_python.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/reference/speed_python.rst b/docs/reference/speed_python.rst index 64fd9df6c..9360fd610 100644 --- a/docs/reference/speed_python.rst +++ b/docs/reference/speed_python.rst @@ -246,6 +246,13 @@ There are certain limitations in the current implementation of the native code e * Context managers are not supported (the ``with`` statement). * Generators are not supported. * If ``raise`` is used an argument must be supplied. +* The background scheduler (see `micropython.schedule`) is not run during + execution of native code. +* On targets with thrteading and the GIL, the GIL is not released during + execution of native code. + +To mitigate the last two points, long running native functions should call +``time.sleep(0)`` periodically, which will run the scheduler and bounce the GIL. The trade-off for the improved performance (roughly twice as fast as bytecode) is an increase in compiled code size.