Closed beyonlo closed 1 year ago
Thanks for the comments. There are two options I can see:
Do you think setting the threshold serves a useful purpose?
Hello @peterhinch
- Remove the threshold setting.
- Cause it to occur infrequently, such as every N iterations.
I consider number 1 the best option. The reason is the same of answer for the next question.
Do you think setting the threshold serves a useful purpose?
In my opinion it is very useful in some situations, but thinking as global solution of all applications running together, not just about the GUI app for example, even that you set the threshold()
as a fixed value (without using gc.mem_free()/gc.mem_alloc())
to not have much cost time. If one app (not the GUI) is allocating much RAM (but less than GUI) and the microcontroller has very little RAM, maybe user need to set a smaller global threshold
than are setting on the GUI. So, there are different situations where in my vision the best option is that user know about all applications running and set manually the threshold() in one, or more specific points of code, if necessary. In the mostly cases, user will never need to set the gc.threshold()
. I see two situations where use it is very useful:
RAM
in a shot than there is available, that's will cause memory error. So user need to set a global gc.threshold()
gc.collect()
is using more time than you want for your solution. So if you set for example gc.threshold(4000)
, each 4000 bytes allocated, the gc.collect()
will be called, and the time to collect 4000 bytes is a good time for your application. That's is especially good for SPIRAM,
but very useful too in no SPIRAM
where you need some kind of real solution where hard interruption (that stop the GC)
can't be used or in cases that microcontroller
do not have that kind of interruption (like as ESP32 family
) where the interruption will be delayed by GC.
In my opinion I strongly do not recommend to use gc.mem_free()/gc.mem_alloc())
as a way to do any calculation or/and check how much RAM still is free/allocated to do something, because that has very high cost time. It is very good for debug, and/or when are developing, but as production is not a good idea.
OK, I'm convinced. Now done.
Hello @peterhinch
I see that you added this fetaure: March 2022: Add latency control for hosts with SPIRAM.
I'm working just with nanogui, but I want to use microgui in the future - good work :)
This code below is from here
I don't know if you know, but the cost of time to run
gc.mem_alloc()
orgc.mem_free()
is *near time than rungc.collect()
. *near depends of port/platform, but some times is more.Well, if you run
gc.threshold(gc.mem_free() // 4 + gc.mem_alloc())
every (500ms), so you have the time ofgc.collect()
+ the time ofgc.mem_free()
+ the time ofgc.mem_alloc()
. So, in my perception, doing that, you have ~200% more cost time than if you run only thegc.collect()
. Am I correct? If yes, in my opinion, maybe a option is consider to do thethreshold
calc and rungc.threshold()
not every time, but just one time in some place with a default/or configured by user (need to think better).Look below that using the
ESP32-S3
with noSPIRAM
(just internal), thegc.collect()
is ~2ms, thegc.mem_free()
is ~5ms and thegc.mem_alloc()
is ~5ms. And when set thegc.threshold()
the time used is ~9ms. So in case that use ESP32-S3 chip the cost time of that loop withgc.threshold()
is ~500% more than justgc.collect()
, because every 500ms loop have cost time of ~11ms (9 +2), and if does only thegc.collect()
the cost time will be ~2ms.Thank you very much for your attention!