From e38e57d00a7b5f49e53188da84bd8432626b13be Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Tue, 20 May 2025 16:41:51 +0200 Subject: [PATCH] modify things --- draft_code/saved_functions.py | 8 ++++++++ .../apps/com.example.cputest/assets/cputest.py | 5 +++++ internal_filesystem/lib/websocket.py | 4 ++-- internal_filesystem/lib/websocket_nostr_receive.py | 6 +++--- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/draft_code/saved_functions.py b/draft_code/saved_functions.py index 9164790b..57e26b13 100644 --- a/draft_code/saved_functions.py +++ b/draft_code/saved_functions.py @@ -656,3 +656,11 @@ buf.data[1000000] = 0xFF # Write way beyond buffer size # this works to crash it: from machine import mem32 mem32[0] = 0xDEADBEEF + + + +# testing stack size: recursion depth * 256 +#normally I get ~16KB + +import _thread +_thread.stack_size(0) diff --git a/internal_filesystem/apps/com.example.cputest/assets/cputest.py b/internal_filesystem/apps/com.example.cputest/assets/cputest.py index 79ac1410..08e4b7b5 100644 --- a/internal_filesystem/apps/com.example.cputest/assets/cputest.py +++ b/internal_filesystem/apps/com.example.cputest/assets/cputest.py @@ -20,6 +20,11 @@ # Busy loop with yield: 46000 iterations/second => this went up 25% # SHA-256 (1KB): 5100 iterations/second # +# When the nostr thing is hanging: +# Busy loop: 102000 iterations/second +# Busy loop with yield: 12000 iterations/second => this went down 70%! +# SHA-256 (1KB): 5100 iterations/second +# # Results on desktop: # Busy loop: 15 997 000 => 125x faster # Busy loop with yield: 10 575 000 => 229x faster diff --git a/internal_filesystem/lib/websocket.py b/internal_filesystem/lib/websocket.py index 4bcd7e0a..4810d1aa 100644 --- a/internal_filesystem/lib/websocket.py +++ b/internal_filesystem/lib/websocket.py @@ -299,7 +299,7 @@ class WebSocketApp: async for msg in ws: import micropython print(f"websocket.py _connect_and_run thread stack used: {micropython.stack_use()}") - _log_debug(f"websocket.py _connect_and_run received msg: type={msg.type}, length: {len(msg.data)} and data={str(msg.data)[:50]}...") + _log_debug(f"websocket.py _connect_and_run received msg: type={msg.type}, length: {len(msg.data)} and data={str(msg.data)[:70]}...") if not self.running: _log_debug("Not running, breaking message loop") break @@ -325,7 +325,7 @@ class WebSocketApp: async def _send_async(self, data, opcode): """Async send implementation.""" - _log_debug(f"Sending: opcode={opcode}, data={str(data)[:20]}...") + _log_debug(f"Sending: opcode={opcode}, data={str(data)[:90]}...") try: if opcode == ABNF.OPCODE_TEXT: await self.ws.send_str(data) diff --git a/internal_filesystem/lib/websocket_nostr_receive.py b/internal_filesystem/lib/websocket_nostr_receive.py index c1998c04..5b31d19b 100644 --- a/internal_filesystem/lib/websocket_nostr_receive.py +++ b/internal_filesystem/lib/websocket_nostr_receive.py @@ -82,9 +82,9 @@ def printevents(): # 24KB is fine # somehow, if I run this in a thread, I get: can't create thread" at File "/lib/nostr/relay_manager.py", line 48, in open_connections # tried stack sizes from 18KB up to 32KB -#_thread.stack_size(48*1024) -#_thread.start_new_thread(printevents, ()) -printevents() +_thread.stack_size(16*1024) +_thread.start_new_thread(printevents, ()) +#printevents() #import gc