Skip to content

Commit 43e3b0f

Browse files
feat: perform garbage collection only, if no event is in queue
1 parent 117c01a commit 43e3b0f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

components/esp32-javascript/esp32-javascript.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,6 @@ static void createConsole(duk_context *ctx)
402402

403403
static duk_ret_t el_suspend(duk_context *ctx)
404404
{
405-
// force garbage collection 2 times see duktape doc
406-
// greatly increases perfomance with external memory
407-
duk_gc(ctx, 0);
408-
duk_gc(ctx, 0);
409405
// feed watchdog
410406
vTaskDelay(1);
411407

@@ -416,6 +412,16 @@ static duk_ret_t el_suspend(duk_context *ctx)
416412
int arr_idx = duk_push_array(ctx);
417413
int arrsize = 0;
418414
TickType_t timeout = portMAX_DELAY;
415+
416+
// If event queue is empty its time for a manually started garbage collection
417+
if (uxQueueMessagesWaiting(el_event_queue) == 0)
418+
{
419+
// force garbage collection 2 times see duktape doc
420+
// greatly increases perfomance with external memory
421+
duk_gc(ctx, 0);
422+
duk_gc(ctx, 0);
423+
}
424+
419425
while (xQueueReceive(el_event_queue, &events, timeout) == pdTRUE)
420426
{
421427
timeout = 0; // set timeout to 0 to not wait in while loop if there are no more events available

0 commit comments

Comments
 (0)