aboutsummaryrefslogtreecommitdiff
path: root/py/gc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-05-12 22:09:34 +1000
committerDamien George <damien.p.george@gmail.com>2018-05-13 22:53:28 +1000
commit749b16174b5292b2680ab027a6a1b3874e22ea43 (patch)
tree874961d6fc06db8e6813f5da0398ece013241255 /py/gc.c
parentaeaace0737f5c2c305f163d6d61617cfd7faf4ce (diff)
py/mpstate.h: Adjust start of root pointer section to exclude non-ptrs.
This patch moves the start of the root pointer section in mp_state_ctx_t so that it skips entries that are not pointers and don't need scanning. Previously, the start of the root pointer section was at the very beginning of the mp_state_ctx_t struct (which is the beginning of mp_state_thread_t). This was the original assembler version of the NLR code was hard-coded to have the nlr_top pointer at the start of this state structure. But now that the NLR code is partially written in C there is no longer this restriction on the location of nlr_top (and a comment to this effect has been removed in this patch). So now the root pointer section starts part way through the mp_state_thread_t structure, after the entries which are not root pointers. This patch also moves the non-pointer entries for MICROPY_ENABLE_SCHEDULER outside the root pointer section. Moving non-pointer entries out of the root pointer section helps to make the GC more precise and should help to prevent some cases of collectable garbage being kept. This patch also has a measurable improvement in performance of the pystone.py benchmark: on unix x86-64 and stm32 there was an improvement of roughly 0.6% (tested with both gcc 7.3 and gcc 8.1).
Diffstat (limited to 'py/gc.c')
-rw-r--r--py/gc.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/py/gc.c b/py/gc.c
index 84c9918fd..38de51399 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -328,7 +328,9 @@ void gc_collect_start(void) {
// correctly in the mp_state_ctx structure. We scan nlr_top, dict_locals,
// dict_globals, then the root pointer section of mp_state_vm.
void **ptrs = (void**)(void*)&mp_state_ctx;
- gc_collect_root(ptrs, offsetof(mp_state_ctx_t, vm.qstr_last_chunk) / sizeof(void*));
+ size_t root_start = offsetof(mp_state_ctx_t, thread.dict_locals);
+ size_t root_end = offsetof(mp_state_ctx_t, vm.qstr_last_chunk);
+ gc_collect_root(ptrs + root_start / sizeof(void*), (root_end - root_start) / sizeof(void*));
#if MICROPY_ENABLE_PYSTACK
// Trace root pointers from the Python stack.